Instructions

This file (hdat9600_final_assignment.Rmd) is the R Markdown document in which you need to complete your HDAT9600 final assignment. This assignment is assessed and will count for 30% of the total course marks. The assignment comprises two tasks worth 15 marks each. The first task will focus on logistic regression, and the second task will focus on survival analysis. There is no word limit, but a report of about 10 pages in length when printed (except that it will not be printed) is appropriate.

Don’t hesitate to ask the course convenor for help via OpenLearning. The course instructor are happy to point you in the right direction and to make suggestions, but they won’t, of course, complete your assignments for you!

Data for this assignment

The data used for this assignment consist of records from Intensive Care Unit (ICU) hospital stays in the USA. All patients were adults who were admitted for a wide variety of reasons. ICU stays of less than 48 hours have been excluded.

The source data for the assignment are data made freely available for the 2012 MIT PhysioNet/Computing for Cardiology Challenge. Details are provided here. Training Set A data have been used. The original data has been modified and assembled to suit the purpose of this assignment. While not required for the purposes of this assignment, full details of the preparatory work can be found in the hdat9600_final_assignment_data_preparation file.

The dataframe consists of 120 variables, which are defined as follows:

Patient Descriptor Variables

  • RecordID: a unique integer for each ICU stay
  • Age: years
  • Gender: male/female
  • Height: cm
  • ICUType: Coronary Care Unit; Cardiac Surgery Recovery Unit; Medical ICU; Surgical ICU
  • Length_of_stay: The number of days between the patient’s admission to the ICU and the end of hospitalisation
  • Survival: The number of days between ICU admission and death for patients who died
  • Outcome Variables

  • in_hospital_death: 0:survivor/1:died in-hospital this is the outcome variable for Task 1: Logistic Regression
  • Status: True/False this is the censoring variable for Task 2: Survival Analysis
  • Days: Length of survival (in days) this is the survival time variable for Task 2: Survival Analysis
  • Clinical Variables

    Use the hyperlinks below to find out more about the clinical meaning of each variable. The first two clinical variables are summary scores that are used to assess patient condition and risk.

  • SAPS-I score [Simplified Acute Physiological Score (Le Gall et al., 1984)]
  • SOFA score [Sequential Organ Failure Assessment (Ferreira et al., 2001)]
  • The following 36 clinical measures were assessed at multiple timepoints during each patient’s ICU stay. For each of the 36 clinical measures, you are given 3 summary variables: a) The minimum value during the first 24 hours in ICU (_min), b) The maximum value during the first 24 hours in ICU (_max), and c) The difference between the mean and the most extreme values during the first 24 hours in ICU (_diff). For example, for the clinical measure Cholesterol, these three variables are labelled ‘Cholesterol_min’, ‘Cholesterol_max’, and ‘Cholesterol_diff’.

  • Albumin (g/dL)
  • ALP [Alkaline phosphatase (IU/L)]
  • ALT [Alanine transaminase (IU/L)]
  • AST [Aspartate transaminase (IU/L)]
  • Bilirubin (mg/dL)
  • BUN [Blood urea nitrogen (mg/dL)]
  • Cholesterol (mg/dL)
  • Creatinine [Serum creatinine (mg/dL)]
  • DiasABP [Invasive diastolic arterial blood pressure (mmHg)]
  • FiO2 [Fractional inspired O2 (0-1)]
  • GCS [Glasgow Coma Score (3-15)]
  • Glucose [Serum glucose (mg/dL)]
  • HCO3 [Serum bicarbonate (mmol/L)]
  • HCT [Hematocrit (%)]
  • HR [Heart rate (bpm)]
  • K [Serum potassium (mEq/L)]
  • Lactate (mmol/L)
  • Mg [Serum magnesium (mmol/L)]
  • MAP [Invasive mean arterial blood pressure (mmHg)]
  • MechVent [Mechanical ventilation respiration (0:false, or 1:true)]
  • Na [Serum sodium (mEq/L)]
  • NIDiasABP [Non-invasive diastolic arterial blood pressure (mmHg)]
  • NIMAP [Non-invasive mean arterial blood pressure (mmHg)]
  • NISysABP [Non-invasive systolic arterial blood pressure (mmHg)]
  • PaCO2 [partial pressure of arterial CO2 (mmHg)]
  • PaO2 [Partial pressure of arterial O2 (mmHg)]
  • pH [Arterial pH (0-14)]
  • Platelets (cells/nL)
  • RespRate [Respiration rate (bpm)]
  • SaO2 [O2 saturation in hemoglobin (%)]
  • SysABP [Invasive systolic arterial blood pressure (mmHg)]
  • Temp [Temperature (°C)]
  • TropI [Troponin-I (μg/L)]
  • TropT [Troponin-T (μg/L)]
  • Urine [Urine output (mL)]
  • WBC [White blood cell count (cells/nL)]
  • Weight (kg)
  • Accessing the Data

    The data frame can be loaded with the following code:

    # import required packages
    library(ggplot2)
    library(gridExtra)
    library(magrittr)
    library(dplyr)
    ## 
    ## Attaching package: 'dplyr'
    ## The following object is masked from 'package:gridExtra':
    ## 
    ##     combine
    ## The following objects are masked from 'package:stats':
    ## 
    ##     filter, lag
    ## The following objects are masked from 'package:base':
    ## 
    ##     intersect, setdiff, setequal, union
    library(survival)
    library(eha)
    library(stringi)
    library(bshazard)
    ## Loading required package: splines
    ## Loading required package: Epi
    library(survminer)
    ## Loading required package: ggpubr
    # Getting the path of your current open file
    # Extra code to ensure this file imports data in local directory
    library(rstudioapi)
    current_path <- rstudioapi::getActiveDocumentContext()$path 
    setwd(dirname(current_path ))
    
    # import data
    icu_patients_df0 <- readRDS("icu_patients_df0.rds")
    icu_patients_df1 <- readRDS("icu_patients_df1.rds")

    Note: icu_patients_df1 is an imputed (i.e. missing values are ‘derived’) version of icu_patients_df0. This assignment does not concern the methods used for imputation.

    Task 1 (15 marks)

    In this task, you are required to develop a logistic regression model using the icu_patients_df1 data set which adequately explains or predicts the in_hospital_death variable as the outcome using a subset of the available predictor variables. You should fit a series of models, evaluating each one, before you present your final model. Your final model should not include all the predictor variables, just a small subset of them, which you have selected based on statistical significance and/or background knowledge. It is perfectly acceptable to include predictor variables in your final model which are not statistically significant, as long as you justify their inclusion on medical or physiological grounds (you will not be marked down if your medical justification is not exactly correct or complete, but do you best). Aim for between five and ten predictor variables (slightly more or fewer is OK). You should assess each model you consider for goodness of fit and other relevant statistics to help you choose between them. For your final model, present a set of diagnostic statistics and/or charts and comment on them. You don’t need to do an exhaustive exploratory data analysis of all the variables in the data set, but you should examine those variables that you use in your model. Finally, re-fit your final model to the unimputed data frame (icu_patients_df0.rds) and comment on any differences you find compared to the same model fitted to the imputed data.

    Hints

    1. Select an initial subset of explanatory variables that you will use to predict the risk of in-hospital death. Justify your choice.

    2. Conduct basic exploratory data analysis on your variables of choice.

    3. Fit appropriate univariate logistic regression models.

    To select a subset of explanatory variables, we have examined the SAPS1 score and the SOFA scores included in the dataset in more detail to ascertain which variables could be logically associated with increased mortality and poor survival. We have also assessed the clinical measures used to calculate the APACHE score which is another commonly used measure in ICU risk prediction models.

    1. Write a paragraph summarising the most important findings of your final model. Include the most important values from the statistical output, and a simple clinical interpretation.

    Task 1 Response:

    Select an initial subset of explanatory variables:

    The purpose of this task is to understand the impact of information collected during the first 24 hours of an ICU stay on in-hospital mortality of the ICU population.

    To select a subset of explanatory variables, we have examined the SAPS1 score and the SOFA scores included in the dataset in more detail to ascertain which variables could be logically associated with increased mortality and poor survival. We have also assessed the clinical measures used to calculate the APACHE score which is another commonly used measure in ICU risk prediction models.

    SAPS1 - Simplified Acute Physiology Score is a measure of the severity of disease for patients admitted to ICU. The following measures increases the SAPS1 score:

    • Advanced Age
    • Low and high Heart Rate
    • Low and high Systolic Blood Pressure
    • High Temperature
    • Low Glasgow Coma Scale (However it is most meaningful to use the highest GCS score available for prognostication)
    • Mechanical Ventilation or CPAP
    • High PaO2/ FiO2 ratio (It is likely that highest FiO2 is administered during lowest PaO2)
    • Low Urine Output
    • High Blood Urea Nitrogen
    • Low or High Sodium
    • Low or high Potassium
    • Low Bicarbonate
    • High Bilirubin
    • Low or High White Blood Cell
    • Chronic diseases
    • Type of admission (ie ICU Type)

    SOFA - sequential organ failure assessment is a predictor of ICU mortality. The following measures increase the SOFA score:

    • Elevated PaO2/ FiO2 ratio-
    • Reduced GCS - Nervous system
    • Reduced MAP - Cardiovascular system
    • Administration of vasopressors - Cardiovascular system
    • High Bilirubin - Liver
    • Low Platelets - Coagulation
    • High Creatinine - Kidneys
    • Low Urine - Kidneys

    The APACHE score is commonly used validated risk score for ICU risk prediction. The variables that increase the APACHE score include:

    • Advanced Age
    • High or Low Temperature
    • High or Low MAP
    • High or Low HR
    • High or Low Respiratory Rate
    • High PaO2/FiO2 ratio
    • High or Low pH
    • High or Low Na
    • High or Low K
    • High Creatinine
    • High or low HCT
    • High or Low WBC

    In the exploratory analysis, we include variables that will increase SOFA, SAPS or APACHE scores (note that higher SOFA, SAPS and APACHE scores are associated with higher risk of mortality). For example, increased BUN and reduced HCO3 will increase the SAPS score, therefore we will include BUN_max (but not BUN_min and BUN_diff) and HCO3_min (but not HCO3_max and HCO3_diff). Where both extremes of a variable will increase the risk score, both min and max variables will be included.

    Other factors known to be associated with morbidity/ mortality not included in risk scores: * Height/ weight - Body composition/ BMI is associated with mortality and survival * Gender - Males are typically associated with high risk of mortality * Glucose - high and low Glucose levels are associated with pathology * Troponin T and I - high troponin results (cardiac biomarkers) associated with morbidity and mortality * Lactate - elevated lactate is associated with poor organ perfusion and ICU morbidity/ mortality * Albumin - reduced albumin is associated with poor clinical outcomes

    Therefore, the initial subset of explanatory variables we have chosen for this task are:

    DEMOGRAPHIC VARIABLES:
    * Age
    * Gender
    * ICUType
    * Height
    * Weight_max

    CLINICAL VARIABLES:
    * Albumin_min
    * Bilirubin_max
    * BUN_max
    * Creatinine_max

    * GCS_min
    * Glucose_min and Glucose_max
    * HCO3_min
    * HR_min and HR_max
    * K_min and K_max
    * Lactate_max
    * MAP_min
    * Na_min and Na_max
    * NISysABP_min and NISysABP_max
    * Platelets_min
    * FiO2_max and PaO2_min - included as PFratio= PaO2_min/ FiO2_max
    * pH_min and pH_max
    * RespRate_min and RespRate_max
    * Temp_min and Temp_max
    * TroponinI_max
    * TroponinT_max
    * Urine_min
    * WBC_min and WBC_max

    Basic initial exploratory data analysis (EDA):

    # create new variable PF ratio as part of our list of variables to include
    icu_patients_df1$PFratio<-icu_patients_df1$PaO2_min/icu_patients_df1$FiO2_max
    icu_patients_df0$PFratio<-icu_patients_df0$PaO2_min/icu_patients_df0$FiO2_max
    
    # create a vector of the variables chosen to explore
    explore_vars <- c('Age', 'Gender', 'ICUType', 'Height', 'Weight_max', 
                      'Albumin_min', 'Bilirubin_max', 'BUN_max', 'Creatinine_max', 
                      'GCS_min', 'Glucose_min', 'Glucose_max', 'HCO3_min', 'HR_min', 
                      'HR_max', 'K_min', 'K_max', 'Lactate_max', 'MAP_min', 
                      'Na_min', 'Na_max', 'NISysABP_min', 'NISysABP_max', 
                      'Platelets_min', 'PFratio', 'pH_min', 'pH_max', 
                      'RespRate_min', 'RespRate_max', 'Temp_min', 'Temp_max', 
                      'TroponinI_max', 'TroponinT_max', 'Urine_min', 'WBC_min', 
                      'WBC_max')
    
    # examine the summary output for each chosen variable
    summary(icu_patients_df1[,explore_vars])
    ##       Age           Gender                              ICUType   
    ##  Min.   :16.00   Female: 913   Coronary Care Unit           :297  
    ##  1st Qu.:52.00   Male  :1148   Cardiac Surgery Recovery Unit:448  
    ##  Median :67.00                 Medical ICU                  :788  
    ##  Mean   :64.41                 Surgical ICU                 :528  
    ##  3rd Qu.:78.00                                                    
    ##  Max.   :90.00                                                    
    ##                                                                   
    ##      Height        Weight_max      Albumin_min    Bilirubin_max   
    ##  Min.   : 13.0   Min.   : 34.60   Min.   :1.100   Min.   : 0.100  
    ##  1st Qu.:162.6   1st Qu.: 66.00   1st Qu.:2.600   1st Qu.: 0.400  
    ##  Median :170.2   Median : 80.00   Median :3.000   Median : 0.700  
    ##  Mean   :170.0   Mean   : 82.66   Mean   :3.012   Mean   : 1.739  
    ##  3rd Qu.:177.8   3rd Qu.: 94.55   3rd Qu.:3.500   3rd Qu.: 1.300  
    ##  Max.   :426.7   Max.   :230.00   Max.   :5.300   Max.   :45.900  
    ##  NA's   :992     NA's   :146                                      
    ##     BUN_max       Creatinine_max      GCS_min        Glucose_min   
    ##  Min.   :  3.00   Min.   : 0.200   Min.   : 3.000   Min.   : 24.0  
    ##  1st Qu.: 14.00   1st Qu.: 0.800   1st Qu.: 3.000   1st Qu.: 98.0  
    ##  Median : 20.00   Median : 1.000   Median : 8.000   Median :117.0  
    ##  Mean   : 27.48   Mean   : 1.499   Mean   : 8.773   Mean   :124.8  
    ##  3rd Qu.: 33.00   3rd Qu.: 1.500   3rd Qu.:14.000   3rd Qu.:141.0  
    ##  Max.   :197.00   Max.   :22.000   Max.   :15.000   Max.   :632.0  
    ##                                                                    
    ##   Glucose_max        HCO3_min         HR_min           HR_max     
    ##  Min.   :  39.0   Min.   : 5.00   Min.   :  0.00   Min.   : 44.0  
    ##  1st Qu.: 117.0   1st Qu.:20.00   1st Qu.: 61.00   1st Qu.: 91.0  
    ##  Median : 141.0   Median :23.00   Median : 71.00   Median :104.0  
    ##  Mean   : 163.3   Mean   :22.43   Mean   : 71.99   Mean   :106.6  
    ##  3rd Qu.: 180.0   3rd Qu.:25.00   3rd Qu.: 81.00   3rd Qu.:119.0  
    ##  Max.   :1143.0   Max.   :44.00   Max.   :126.00   Max.   :300.0  
    ##                                                                   
    ##      K_min          K_max         Lactate_max        MAP_min      
    ##  Min.   :1.80   Min.   : 2.500   Min.   : 0.400   Min.   :  1.00  
    ##  1st Qu.:3.50   1st Qu.: 4.000   1st Qu.: 1.500   1st Qu.: 55.00  
    ##  Median :3.90   Median : 4.300   Median : 2.200   Median : 61.00  
    ##  Mean   :3.95   Mean   : 4.419   Mean   : 2.773   Mean   : 62.76  
    ##  3rd Qu.:4.30   3rd Qu.: 4.700   3rd Qu.: 3.200   3rd Qu.: 70.00  
    ##  Max.   :6.90   Max.   :22.900   Max.   :29.300   Max.   :265.00  
    ##                                                                   
    ##      Na_min        Na_max       NISysABP_min     NISysABP_max   Platelets_min  
    ##  Min.   : 98   Min.   :112.0   Min.   :  4.00   Min.   : 78.0   Min.   :  9.0  
    ##  1st Qu.:136   1st Qu.:137.0   1st Qu.: 83.00   1st Qu.:121.0   1st Qu.:126.0  
    ##  Median :138   Median :140.0   Median : 95.00   Median :138.0   Median :184.0  
    ##  Mean   :138   Mean   :139.8   Mean   : 96.55   Mean   :140.5   Mean   :197.9  
    ##  3rd Qu.:141   3rd Qu.:142.0   3rd Qu.:108.00   3rd Qu.:156.0   3rd Qu.:246.0  
    ##  Max.   :160   Max.   :177.0   Max.   :234.00   Max.   :274.0   Max.   :891.0  
    ##                                NA's   :453      NA's   :453                    
    ##     PFratio         pH_min          pH_max       RespRate_min    RespRate_max  
    ##  Min.   :  24   Min.   :3.000   Min.   :7.150   Min.   : 4.00   Min.   :13.00  
    ##  1st Qu.:  85   1st Qu.:7.280   1st Qu.:7.380   1st Qu.:12.00   1st Qu.:24.00  
    ##  Median : 122   Median :7.340   Median :7.420   Median :14.00   Median :27.00  
    ##  Mean   : 154   Mean   :7.327   Mean   :7.418   Mean   :14.25   Mean   :29.12  
    ##  3rd Qu.: 188   3rd Qu.:7.390   3rd Qu.:7.460   3rd Qu.:17.00   3rd Qu.:33.00  
    ##  Max.   :1150   Max.   :7.630   Max.   :7.690   Max.   :24.00   Max.   :98.00  
    ##                                                                                
    ##     Temp_min        Temp_max     TroponinI_max   TroponinT_max    
    ##  Min.   :24.20   Min.   :35.40   Min.   : 0.30   Min.   : 0.0100  
    ##  1st Qu.:35.60   1st Qu.:37.10   1st Qu.: 2.60   1st Qu.: 0.0600  
    ##  Median :36.10   Median :37.60   Median : 7.80   Median : 0.1700  
    ##  Mean   :36.01   Mean   :37.69   Mean   :11.83   Mean   : 0.9079  
    ##  3rd Qu.:36.60   3rd Qu.:38.20   3rd Qu.:17.60   3rd Qu.: 0.8000  
    ##  Max.   :38.30   Max.   :42.10   Max.   :43.40   Max.   :24.4600  
    ##                                                                   
    ##    Urine_min         WBC_min          WBC_max      
    ##  Min.   :  0.00   Min.   :  0.10   Min.   :  0.10  
    ##  1st Qu.:  0.00   1st Qu.:  7.60   1st Qu.:  9.30  
    ##  Median : 20.00   Median : 10.40   Median : 12.30  
    ##  Mean   : 34.55   Mean   : 11.51   Mean   : 13.95  
    ##  3rd Qu.: 36.00   3rd Qu.: 14.10   3rd Qu.: 16.90  
    ##  Max.   :600.00   Max.   :128.30   Max.   :155.60  
    ## 
    # Write a function to plot box plots for each variable by in_hospital_death
    boxplot_eda <- function(variable){
      plot <- ggplot(data=icu_patients_df1, 
              mapping = aes(x = in_hospital_death=="1", 
                            y = icu_patients_df1[,variable])) + 
              geom_boxplot() +
              labs(title=paste('Box plot of',variable), 
                   x='In hospital death', y=variable)
      return(plot)
    }
    
    
    # Continuous variables EDA and their interpretation
    
    # continuous variables from the list of initial subset of explanatory variables
    cont_vars <- c('Age', 'Height', 'Weight_max', 'Albumin_min', 'Bilirubin_max',
                   'BUN_max', 'Creatinine_max', 'GCS_min', 'Glucose_min',
                   'Glucose_max', 'HCO3_min', 'HR_min', 'HR_max', 'K_min', 'K_max',
                   'Lactate_max', 'MAP_min', 'Na_min', 'Na_max', 'NISysABP_min',
                   'NISysABP_max', 'Platelets_min', 'PFratio', 'pH_min', 'pH_max',
                   'RespRate_min', 'RespRate_max', 'Temp_min', 'Temp_max',
                   'TroponinI_max', 'TroponinT_max', 'Urine_min', 'WBC_min', 'WBC_max')
    
    # Loop through the continuous variables and produce box plots using the boxplot_eda() function 
    b <- list() # initialise an empty list to store the plots in
    for(i in 1:length(cont_vars)){
      b[[i]] <- boxplot_eda(cont_vars[i])
    }
    # arrange the list of plots in a 12 row grid using grid.arrange() from package{gridExtra}
    do.call(grid.arrange, c(b, nrow = 12))
    ## Warning: Removed 992 rows containing non-finite values (stat_boxplot).
    ## Warning: Removed 146 rows containing non-finite values (stat_boxplot).
    ## Warning: Removed 453 rows containing non-finite values (stat_boxplot).
    
    ## Warning: Removed 453 rows containing non-finite values (stat_boxplot).

    # Patients who died had higher SAPS1 and SOFA scores
    ggplot(data=icu_patients_df1, 
           mapping = aes(x = in_hospital_death=="1", y = SAPS1)) + geom_boxplot() +
           labs(title=paste('Box plot of SAPS1 scores'), 
                x='In hospital death', y='SAPS1 score')
    ## Warning: Removed 96 rows containing non-finite values (stat_boxplot).

    ggplot(data=icu_patients_df1, 
           mapping = aes(x = in_hospital_death=="1", y = SOFA)) + geom_boxplot() +
           labs(title=paste('Box plot of SOFA scores'), 
                x='In hospital death', y='SOFA score')

    ### Categorical variables EDA and their interpretation ###
    
    # cardiac surgery recovery unit have a smaller death circle compared to the other 3 ICU units
    # ie less proportion of in hospital deaths compared to alive
    icutype_plot <- ggplot(data=icu_patients_df1, 
                           mapping = aes(x = in_hospital_death=="1", y = ICUType)) + 
                    geom_count(aes(size = after_stat(prop), group = ICUType)) + 
                    scale_size_area(max_size = 10) + 
                    labs(title=paste('Proportion of patients by ICU type'), 
                         x='In hospital death', size='Proportion of patients')
    
    # difficult to say, roughly same amount of men/women died as a proportion of the alive group
    gender_plot <- ggplot(data=icu_patients_df1, 
                          mapping = aes(x = in_hospital_death=="1", y = Gender)) + 
                   geom_count(aes(size = after_stat(prop), group = ICUType)) + 
                   scale_size_area(max_size = 20) + 
                    labs(title=paste('Proportion of patients by gender'), 
                         x='In hospital death', size='Proportion of patients')
    
    # arrange the categorical variable plots side-by-side
    grid.arrange(icutype_plot, gender_plot, nrow=1)

    EDA Findings:

    • There are 2061 unique individuals in the dataset. Of these, 913 are female (44%) and 1148 are male (56%).

    • There were 297 deaths out of 2061 observations, which is a risk rate of 14.4% (not an uncommon event).

    • Medical ICU accounted for 38% of individuals, 26% in Surgical ICU, 24% in Cardiac Surgery recovery Unit and 14% in the Coronary Care unit.

    • The following variables have a large proportion of missing observations:

      • Weight_max - 146 missing observations
      • Height - 992 missing observations
      • NISysABP_min & NISysABP_max - 453 missing observations
    • Proportion of in hospital deaths were observed for each variable:

      • Those that died had higher SAPS1 and SOFA scores.
      • Females had higher proportion of deaths than males.
      • Medical ICU had a greatest rate of mortality, whereas Cardiac Surgery recovery unit had the lowest porportion of deaths.
      • Higher age in those that died
      • Higher min albumin in those that died
      • Slightly higher max bilirubin in those that died
      • Higher max (BUN) urea in those that died
      • Higher max creatinine in those that died
      • Lower GCS min in those that died
      • Similar min glucose in both groups
      • Slightly higher max glucose in those that died
      • Lower min HCO3 in those that died
      • Similar min HR in both groups
      • Slightly higher max HR in those that died
      • Similar min K in both groups
      • Similar max K in both groups
      • Slightly higher max lactate in those that died
      • Similar min MAP in both groups
      • Similar min Na in both groups
      • Similar max Na in both groups
      • Slightly lower min NISysABP in those that died
      • Similar max NISysABP in both groups
      • Similar min platelets in both groups
      • Similar PF ratio in both groups
      • Similar min pH in both groups - one extreme outlier
      • Similar pH max in both groups
      • Higher min RR in those that died
      • Higher max RR in those that died
      • Similar min temp in both groups
      • Similar max temp in both groups
      • Similar max troponinI in both groups
      • Similar max troponinT in both groups
      • Similar min urine in both groups
      • Slightly higher min WBC in those that died
      • Slightly higher max WBC in those that died

    Univariate logistic regression models:

    # Univariate logistic regression comparisons for all initial selected variables
    
    age_glm <- glm(in_hospital_death ~ Age, data=icu_patients_df1, family="binomial")
    summary(age_glm) # is significant
    ## 
    ## Call:
    ## glm(formula = in_hospital_death ~ Age, family = "binomial", data = icu_patients_df1)
    ## 
    ## Deviance Residuals: 
    ##     Min       1Q   Median       3Q      Max  
    ## -0.7522  -0.6264  -0.5111  -0.3919   2.5135  
    ## 
    ## Coefficients:
    ##              Estimate Std. Error z value Pr(>|z|)    
    ## (Intercept) -3.761624   0.303337 -12.401  < 2e-16 ***
    ## Age          0.029376   0.004229   6.947 3.73e-12 ***
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## (Dispersion parameter for binomial family taken to be 1)
    ## 
    ##     Null deviance: 1699.7  on 2060  degrees of freedom
    ## Residual deviance: 1644.9  on 2059  degrees of freedom
    ## AIC: 1648.9
    ## 
    ## Number of Fisher Scoring iterations: 5
    gender_glm <- glm(in_hospital_death ~ Gender, data=icu_patients_df1, family="binomial")
    summary(gender_glm) # NOT significant
    ## 
    ## Call:
    ## glm(formula = in_hospital_death ~ Gender, family = "binomial", 
    ##     data = icu_patients_df1)
    ## 
    ## Deviance Residuals: 
    ##     Min       1Q   Median       3Q      Max  
    ## -0.5612  -0.5612  -0.5553  -0.5553   1.9728  
    ## 
    ## Coefficients:
    ##             Estimate Std. Error z value Pr(>|z|)    
    ## (Intercept) -1.76894    0.09381 -18.856   <2e-16 ***
    ## GenderMale  -0.02281    0.12615  -0.181    0.856    
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## (Dispersion parameter for binomial family taken to be 1)
    ## 
    ##     Null deviance: 1699.7  on 2060  degrees of freedom
    ## Residual deviance: 1699.7  on 2059  degrees of freedom
    ## AIC: 1703.7
    ## 
    ## Number of Fisher Scoring iterations: 4
    icuType_glm <- glm(in_hospital_death ~ ICUType, data=icu_patients_df1, family="binomial")
    summary(icuType_glm) # cardiac surgery recovery unit is significant
    ## 
    ## Call:
    ## glm(formula = in_hospital_death ~ ICUType, family = "binomial", 
    ##     data = icu_patients_df1)
    ## 
    ## Deviance Residuals: 
    ##     Min       1Q   Median       3Q      Max  
    ## -0.6402  -0.6402  -0.5615  -0.3458   2.3861  
    ## 
    ## Coefficients:
    ##                                      Estimate Std. Error z value Pr(>|z|)    
    ## (Intercept)                           -1.6463     0.1576 -10.443  < 2e-16 ***
    ## ICUTypeCardiac Surgery Recovery Unit  -1.1407     0.2563  -4.451 8.55e-06 ***
    ## ICUTypeMedical ICU                     0.1653     0.1824   0.906    0.365    
    ## ICUTypeSurgical ICU                   -0.1214     0.2001  -0.607    0.544    
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## (Dispersion parameter for binomial family taken to be 1)
    ## 
    ##     Null deviance: 1699.7  on 2060  degrees of freedom
    ## Residual deviance: 1655.3  on 2057  degrees of freedom
    ## AIC: 1663.3
    ## 
    ## Number of Fisher Scoring iterations: 5
    maxWeight_glm <- glm(in_hospital_death ~ Weight_max, data=icu_patients_df1, family="binomial")
    summary(maxWeight_glm) # is significant
    ## 
    ## Call:
    ## glm(formula = in_hospital_death ~ Weight_max, family = "binomial", 
    ##     data = icu_patients_df1)
    ## 
    ## Deviance Residuals: 
    ##     Min       1Q   Median       3Q      Max  
    ## -0.6460  -0.5846  -0.5605  -0.5231   2.1768  
    ## 
    ## Coefficients:
    ##              Estimate Std. Error z value Pr(>|z|)    
    ## (Intercept) -1.246092   0.242568  -5.137 2.79e-07 ***
    ## Weight_max  -0.006212   0.002912  -2.133   0.0329 *  
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## (Dispersion parameter for binomial family taken to be 1)
    ## 
    ##     Null deviance: 1604.2  on 1914  degrees of freedom
    ## Residual deviance: 1599.4  on 1913  degrees of freedom
    ##   (146 observations deleted due to missingness)
    ## AIC: 1603.4
    ## 
    ## Number of Fisher Scoring iterations: 4
    minAlbumin_glm <- glm(in_hospital_death ~ Albumin_min, data=icu_patients_df1, family="binomial")
    summary(minAlbumin_glm) # is significant
    ## 
    ## Call:
    ## glm(formula = in_hospital_death ~ Albumin_min, family = "binomial", 
    ##     data = icu_patients_df1)
    ## 
    ## Deviance Residuals: 
    ##     Min       1Q   Median       3Q      Max  
    ## -0.7948  -0.5887  -0.5385  -0.4595   2.2842  
    ## 
    ## Coefficients:
    ##             Estimate Std. Error z value Pr(>|z|)    
    ## (Intercept) -0.36392    0.29389  -1.238    0.216    
    ## Albumin_min -0.48186    0.09987  -4.825  1.4e-06 ***
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## (Dispersion parameter for binomial family taken to be 1)
    ## 
    ##     Null deviance: 1699.7  on 2060  degrees of freedom
    ## Residual deviance: 1676.0  on 2059  degrees of freedom
    ## AIC: 1680
    ## 
    ## Number of Fisher Scoring iterations: 4
    maxBili_glm <- glm(in_hospital_death ~ Bilirubin_max, data=icu_patients_df1, family="binomial")
    summary(maxBili_glm) # is significant
    ## 
    ## Call:
    ## glm(formula = in_hospital_death ~ Bilirubin_max, family = "binomial", 
    ##     data = icu_patients_df1)
    ## 
    ## Deviance Residuals: 
    ##     Min       1Q   Median       3Q      Max  
    ## -1.3889  -0.5421  -0.5363  -0.5321   2.0174  
    ## 
    ## Coefficients:
    ##               Estimate Std. Error z value Pr(>|z|)    
    ## (Intercept)   -1.90053    0.06866 -27.679  < 2e-16 ***
    ## Bilirubin_max  0.05692    0.01135   5.013 5.35e-07 ***
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## (Dispersion parameter for binomial family taken to be 1)
    ## 
    ##     Null deviance: 1699.7  on 2060  degrees of freedom
    ## Residual deviance: 1676.8  on 2059  degrees of freedom
    ## AIC: 1680.8
    ## 
    ## Number of Fisher Scoring iterations: 4
    maxUrea_glm <- glm(in_hospital_death ~ BUN_max, data=icu_patients_df1, family="binomial")
    summary(maxUrea_glm) # is significant
    ## 
    ## Call:
    ## glm(formula = in_hospital_death ~ BUN_max, family = "binomial", 
    ##     data = icu_patients_df1)
    ## 
    ## Deviance Residuals: 
    ##     Min       1Q   Median       3Q      Max  
    ## -2.0462  -0.5269  -0.4789  -0.4443   2.2309  
    ## 
    ## Coefficients:
    ##              Estimate Std. Error z value Pr(>|z|)    
    ## (Intercept) -2.492189   0.103693 -24.034   <2e-16 ***
    ## BUN_max      0.022610   0.002347   9.634   <2e-16 ***
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## (Dispersion parameter for binomial family taken to be 1)
    ## 
    ##     Null deviance: 1699.7  on 2060  degrees of freedom
    ## Residual deviance: 1607.3  on 2059  degrees of freedom
    ## AIC: 1611.3
    ## 
    ## Number of Fisher Scoring iterations: 4
    maxCr_glm <- glm(in_hospital_death ~ Creatinine_max, data=icu_patients_df1, family="binomial")
    summary(maxCr_glm) # is significant
    ## 
    ## Call:
    ## glm(formula = in_hospital_death ~ Creatinine_max, family = "binomial", 
    ##     data = icu_patients_df1)
    ## 
    ## Deviance Residuals: 
    ##     Min       1Q   Median       3Q      Max  
    ## -1.8627  -0.5433  -0.5270  -0.5151   2.0633  
    ## 
    ## Coefficients:
    ##                Estimate Std. Error z value Pr(>|z|)    
    ## (Intercept)    -2.05087    0.08430 -24.328  < 2e-16 ***
    ## Creatinine_max  0.16325    0.03135   5.208 1.91e-07 ***
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## (Dispersion parameter for binomial family taken to be 1)
    ## 
    ##     Null deviance: 1699.7  on 2060  degrees of freedom
    ## Residual deviance: 1674.4  on 2059  degrees of freedom
    ## AIC: 1678.4
    ## 
    ## Number of Fisher Scoring iterations: 4
    minGCS_glm <- glm(in_hospital_death ~ GCS_min, data=icu_patients_df1, family="binomial")
    summary(minGCS_glm) # is significant
    ## 
    ## Call:
    ## glm(formula = in_hospital_death ~ GCS_min, family = "binomial", 
    ##     data = icu_patients_df1)
    ## 
    ## Deviance Residuals: 
    ##     Min       1Q   Median       3Q      Max  
    ## -0.6238  -0.6238  -0.5394  -0.4853   2.0964  
    ## 
    ## Coefficients:
    ##             Estimate Std. Error z value Pr(>|z|)    
    ## (Intercept) -1.40261    0.12298 -11.405  < 2e-16 ***
    ## GCS_min     -0.04514    0.01317  -3.426 0.000612 ***
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## (Dispersion parameter for binomial family taken to be 1)
    ## 
    ##     Null deviance: 1699.7  on 2060  degrees of freedom
    ## Residual deviance: 1687.7  on 2059  degrees of freedom
    ## AIC: 1691.7
    ## 
    ## Number of Fisher Scoring iterations: 4
    minGlu_glm <- glm(in_hospital_death ~ Glucose_min, data=icu_patients_df1, family="binomial")
    summary(minGlu_glm) # NOT significant
    ## 
    ## Call:
    ## glm(formula = in_hospital_death ~ Glucose_min, family = "binomial", 
    ##     data = icu_patients_df1)
    ## 
    ## Deviance Residuals: 
    ##     Min       1Q   Median       3Q      Max  
    ## -0.7799  -0.5613  -0.5522  -0.5428   2.0271  
    ## 
    ## Coefficients:
    ##              Estimate Std. Error z value Pr(>|z|)    
    ## (Intercept) -1.967537   0.171241 -11.490   <2e-16 ***
    ## Glucose_min  0.001476   0.001253   1.178    0.239    
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## (Dispersion parameter for binomial family taken to be 1)
    ## 
    ##     Null deviance: 1699.7  on 2060  degrees of freedom
    ## Residual deviance: 1698.4  on 2059  degrees of freedom
    ## AIC: 1702.4
    ## 
    ## Number of Fisher Scoring iterations: 4
    maxGlu_glm <- glm(in_hospital_death ~ Glucose_max, data=icu_patients_df1, family="binomial")
    summary(maxGlu_glm) # is significant
    ## 
    ## Call:
    ## glm(formula = in_hospital_death ~ Glucose_max, family = "binomial", 
    ##     data = icu_patients_df1)
    ## 
    ## Deviance Residuals: 
    ##     Min       1Q   Median       3Q      Max  
    ## -1.4117  -0.5572  -0.5343  -0.5162   2.0872  
    ## 
    ## Coefficients:
    ##               Estimate Std. Error z value Pr(>|z|)    
    ## (Intercept) -2.1865370  0.1202802 -18.179  < 2e-16 ***
    ## Glucose_max  0.0023817  0.0005819   4.093 4.25e-05 ***
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## (Dispersion parameter for binomial family taken to be 1)
    ## 
    ##     Null deviance: 1699.7  on 2060  degrees of freedom
    ## Residual deviance: 1684.2  on 2059  degrees of freedom
    ## AIC: 1688.2
    ## 
    ## Number of Fisher Scoring iterations: 4
    minHCO3_glm <- glm(in_hospital_death ~ HCO3_min, data=icu_patients_df1, family="binomial")
    summary(minHCO3_glm) # is significant
    ## 
    ## Call:
    ## glm(formula = in_hospital_death ~ HCO3_min, family = "binomial", 
    ##     data = icu_patients_df1)
    ## 
    ## Deviance Residuals: 
    ##     Min       1Q   Median       3Q      Max  
    ## -0.9781  -0.5748  -0.5165  -0.4634   2.6504  
    ## 
    ## Coefficients:
    ##             Estimate Std. Error z value Pr(>|z|)    
    ## (Intercept) -0.10497    0.29323  -0.358     0.72    
    ## HCO3_min    -0.07675    0.01345  -5.705 1.17e-08 ***
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## (Dispersion parameter for binomial family taken to be 1)
    ## 
    ##     Null deviance: 1699.7  on 2060  degrees of freedom
    ## Residual deviance: 1666.8  on 2059  degrees of freedom
    ## AIC: 1670.8
    ## 
    ## Number of Fisher Scoring iterations: 4
    minHR_glm <- glm(in_hospital_death ~ HR_min, data=icu_patients_df1, family="binomial")
    summary(minHR_glm) # NOT significant
    ## 
    ## Call:
    ## glm(formula = in_hospital_death ~ HR_min, family = "binomial", 
    ##     data = icu_patients_df1)
    ## 
    ## Deviance Residuals: 
    ##     Min       1Q   Median       3Q      Max  
    ## -0.6235  -0.5656  -0.5528  -0.5390   2.1087  
    ## 
    ## Coefficients:
    ##              Estimate Std. Error z value Pr(>|z|)    
    ## (Intercept) -2.108733   0.301434  -6.996 2.64e-12 ***
    ## HR_min       0.004520   0.004052   1.115    0.265    
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## (Dispersion parameter for binomial family taken to be 1)
    ## 
    ##     Null deviance: 1699.7  on 2060  degrees of freedom
    ## Residual deviance: 1698.4  on 2059  degrees of freedom
    ## AIC: 1702.4
    ## 
    ## Number of Fisher Scoring iterations: 4
    maxHR_glm <- glm(in_hospital_death ~ HR_max, data=icu_patients_df1, family="binomial")
    summary(maxHR_glm) # is significant
    ## 
    ## Call:
    ## glm(formula = in_hospital_death ~ HR_max, family = "binomial", 
    ##     data = icu_patients_df1)
    ## 
    ## Deviance Residuals: 
    ##     Min       1Q   Median       3Q      Max  
    ## -1.1194  -0.5733  -0.5402  -0.5067   2.1517  
    ## 
    ## Coefficients:
    ##              Estimate Std. Error z value Pr(>|z|)    
    ## (Intercept) -2.707555   0.303251  -8.928  < 2e-16 ***
    ## HR_max       0.008565   0.002707   3.164  0.00156 ** 
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## (Dispersion parameter for binomial family taken to be 1)
    ## 
    ##     Null deviance: 1699.7  on 2060  degrees of freedom
    ## Residual deviance: 1689.9  on 2059  degrees of freedom
    ## AIC: 1693.9
    ## 
    ## Number of Fisher Scoring iterations: 4
    minK_glm <- glm(in_hospital_death ~ K_min, data=icu_patients_df1, family="binomial")
    summary(minK_glm) # NOT significant
    ## 
    ## Call:
    ## glm(formula = in_hospital_death ~ K_min, family = "binomial", 
    ##     data = icu_patients_df1)
    ## 
    ## Deviance Residuals: 
    ##     Min       1Q   Median       3Q      Max  
    ## -0.6024  -0.5647  -0.5546  -0.5447   2.0345  
    ## 
    ## Coefficients:
    ##             Estimate Std. Error z value Pr(>|z|)    
    ## (Intercept) -1.47413    0.42361  -3.480 0.000502 ***
    ## K_min       -0.07804    0.10660  -0.732 0.464083    
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## (Dispersion parameter for binomial family taken to be 1)
    ## 
    ##     Null deviance: 1699.7  on 2060  degrees of freedom
    ## Residual deviance: 1699.1  on 2059  degrees of freedom
    ## AIC: 1703.1
    ## 
    ## Number of Fisher Scoring iterations: 4
    maxK_glm <- glm(in_hospital_death ~ K_max, data=icu_patients_df1, family="binomial")
    summary(maxK_glm) # NOT significant
    ## 
    ## Call:
    ## glm(formula = in_hospital_death ~ K_max, family = "binomial", 
    ##     data = icu_patients_df1)
    ## 
    ## Deviance Residuals: 
    ##     Min       1Q   Median       3Q      Max  
    ## -1.2402  -0.5620  -0.5512  -0.5380   2.0561  
    ## 
    ## Coefficients:
    ##             Estimate Std. Error z value Pr(>|z|)    
    ## (Intercept) -2.24634    0.28233  -7.956 1.77e-15 ***
    ## K_max        0.10449    0.06153   1.698   0.0895 .  
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## (Dispersion parameter for binomial family taken to be 1)
    ## 
    ##     Null deviance: 1699.7  on 2060  degrees of freedom
    ## Residual deviance: 1697.0  on 2059  degrees of freedom
    ## AIC: 1701
    ## 
    ## Number of Fisher Scoring iterations: 4
    maxLactate_glm <- glm(in_hospital_death ~ Lactate_max, data=icu_patients_df1, family="binomial")
    summary(maxLactate_glm) # is significant
    ## 
    ## Call:
    ## glm(formula = in_hospital_death ~ Lactate_max, family = "binomial", 
    ##     data = icu_patients_df1)
    ## 
    ## Deviance Residuals: 
    ##     Min       1Q   Median       3Q      Max  
    ## -1.1726  -0.5544  -0.5200  -0.4939   2.1212  
    ## 
    ## Coefficients:
    ##             Estimate Std. Error z value Pr(>|z|)    
    ## (Intercept)  -2.1932     0.1005 -21.820  < 2e-16 ***
    ## Lactate_max   0.1372     0.0244   5.625 1.86e-08 ***
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## (Dispersion parameter for binomial family taken to be 1)
    ## 
    ##     Null deviance: 1699.7  on 2060  degrees of freedom
    ## Residual deviance: 1669.5  on 2059  degrees of freedom
    ## AIC: 1673.5
    ## 
    ## Number of Fisher Scoring iterations: 4
    minMAP_glm <- glm(in_hospital_death ~ MAP_min, data=icu_patients_df1, family="binomial")
    summary(minMAP_glm) # NOT significant
    ## 
    ## Call:
    ## glm(formula = in_hospital_death ~ MAP_min, family = "binomial", 
    ##     data = icu_patients_df1)
    ## 
    ## Deviance Residuals: 
    ##     Min       1Q   Median       3Q      Max  
    ## -0.6583  -0.5674  -0.5551  -0.5341   2.4214  
    ## 
    ## Coefficients:
    ##              Estimate Std. Error z value Pr(>|z|)    
    ## (Intercept) -1.413112   0.257434  -5.489 4.04e-08 ***
    ## MAP_min     -0.005926   0.004051  -1.463    0.143    
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## (Dispersion parameter for binomial family taken to be 1)
    ## 
    ##     Null deviance: 1699.7  on 2060  degrees of freedom
    ## Residual deviance: 1697.4  on 2059  degrees of freedom
    ## AIC: 1701.4
    ## 
    ## Number of Fisher Scoring iterations: 4
    minNa_glm <- glm(in_hospital_death ~ Na_min, data=icu_patients_df1, family="binomial")
    summary(minNa_glm) # is significant
    ## 
    ## Call:
    ## glm(formula = in_hospital_death ~ Na_min, family = "binomial", 
    ##     data = icu_patients_df1)
    ## 
    ## Deviance Residuals: 
    ##     Min       1Q   Median       3Q      Max  
    ## -0.9061  -0.5706  -0.5490  -0.5282   2.2298  
    ## 
    ## Coefficients:
    ##             Estimate Std. Error z value Pr(>|z|)  
    ## (Intercept)  2.04227    1.79129   1.140   0.2542  
    ## Na_min      -0.02776    0.01301  -2.133   0.0329 *
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## (Dispersion parameter for binomial family taken to be 1)
    ## 
    ##     Null deviance: 1699.7  on 2060  degrees of freedom
    ## Residual deviance: 1695.3  on 2059  degrees of freedom
    ## AIC: 1699.3
    ## 
    ## Number of Fisher Scoring iterations: 4
    maxNa_glm <- glm(in_hospital_death ~ Na_max, data=icu_patients_df1, family="binomial")
    summary(maxNa_glm) # NOT significant
    ## 
    ## Call:
    ## glm(formula = in_hospital_death ~ Na_max, family = "binomial", 
    ##     data = icu_patients_df1)
    ## 
    ## Deviance Residuals: 
    ##     Min       1Q   Median       3Q      Max  
    ## -0.6176  -0.5615  -0.5573  -0.5491   2.0760  
    ## 
    ## Coefficients:
    ##              Estimate Std. Error z value Pr(>|z|)
    ## (Intercept) -0.664686   1.927556  -0.345    0.730
    ## Na_max      -0.007993   0.013793  -0.580    0.562
    ## 
    ## (Dispersion parameter for binomial family taken to be 1)
    ## 
    ##     Null deviance: 1699.7  on 2060  degrees of freedom
    ## Residual deviance: 1699.4  on 2059  degrees of freedom
    ## AIC: 1703.4
    ## 
    ## Number of Fisher Scoring iterations: 4
    minNISys_ABP_glm <- glm(in_hospital_death ~ NISysABP_min, data=icu_patients_df1, family="binomial")
    summary(minNISys_ABP_glm) # is significant
    ## 
    ## Call:
    ## glm(formula = in_hospital_death ~ NISysABP_min, family = "binomial", 
    ##     data = icu_patients_df1)
    ## 
    ## Deviance Residuals: 
    ##     Min       1Q   Median       3Q      Max  
    ## -0.9728  -0.6135  -0.5731  -0.5005   2.3871  
    ## 
    ## Coefficients:
    ##               Estimate Std. Error z value Pr(>|z|)    
    ## (Intercept)  -0.450605   0.328983  -1.370 0.170783    
    ## NISysABP_min -0.012922   0.003466  -3.728 0.000193 ***
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## (Dispersion parameter for binomial family taken to be 1)
    ## 
    ##     Null deviance: 1403.1  on 1607  degrees of freedom
    ## Residual deviance: 1388.5  on 1606  degrees of freedom
    ##   (453 observations deleted due to missingness)
    ## AIC: 1392.5
    ## 
    ## Number of Fisher Scoring iterations: 4
    maxNISys_ABP_glm <- glm(in_hospital_death ~ NISysABP_max, data=icu_patients_df1, family="binomial")
    summary(maxNISys_ABP_glm) # NOT significant
    ## 
    ## Call:
    ## glm(formula = in_hospital_death ~ NISysABP_max, family = "binomial", 
    ##     data = icu_patients_df1)
    ## 
    ## Deviance Residuals: 
    ##     Min       1Q   Median       3Q      Max  
    ## -0.6098  -0.5886  -0.5846  -0.5799   1.9414  
    ## 
    ## Coefficients:
    ##                Estimate Std. Error z value Pr(>|z|)    
    ## (Intercept)  -1.7826689  0.3544507  -5.029 4.92e-07 ***
    ## NISysABP_max  0.0007759  0.0024679   0.314    0.753    
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## (Dispersion parameter for binomial family taken to be 1)
    ## 
    ##     Null deviance: 1403.1  on 1607  degrees of freedom
    ## Residual deviance: 1403.0  on 1606  degrees of freedom
    ##   (453 observations deleted due to missingness)
    ## AIC: 1407
    ## 
    ## Number of Fisher Scoring iterations: 3
    minPlt_glm <- glm(in_hospital_death ~ Platelets_min, data=icu_patients_df1, family="binomial")
    summary(minPlt_glm) # NOT significant
    ## 
    ## Call:
    ## glm(formula = in_hospital_death ~ Platelets_min, family = "binomial", 
    ##     data = icu_patients_df1)
    ## 
    ## Deviance Residuals: 
    ##     Min       1Q   Median       3Q      Max  
    ## -0.6122  -0.5735  -0.5558  -0.5260   2.2141  
    ## 
    ## Coefficients:
    ##                 Estimate Std. Error z value Pr(>|z|)    
    ## (Intercept)   -1.5693181  0.1352494 -11.603   <2e-16 ***
    ## Platelets_min -0.0010963  0.0006322  -1.734   0.0829 .  
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## (Dispersion parameter for binomial family taken to be 1)
    ## 
    ##     Null deviance: 1699.7  on 2060  degrees of freedom
    ## Residual deviance: 1696.6  on 2059  degrees of freedom
    ## AIC: 1700.6
    ## 
    ## Number of Fisher Scoring iterations: 4
    maxPFratio_glm <- glm(in_hospital_death ~ PFratio, data=icu_patients_df1, family="binomial")
    summary(maxPFratio_glm) # NOT significant
    ## 
    ## Call:
    ## glm(formula = in_hospital_death ~ PFratio, family = "binomial", 
    ##     data = icu_patients_df1)
    ## 
    ## Deviance Residuals: 
    ##     Min       1Q   Median       3Q      Max  
    ## -0.5806  -0.5687  -0.5595  -0.5398   2.1022  
    ## 
    ## Coefficients:
    ##               Estimate Std. Error z value Pr(>|z|)    
    ## (Intercept) -1.6790207  0.1148206 -14.623   <2e-16 ***
    ## PFratio     -0.0006772  0.0006452  -1.049    0.294    
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## (Dispersion parameter for binomial family taken to be 1)
    ## 
    ##     Null deviance: 1699.7  on 2060  degrees of freedom
    ## Residual deviance: 1698.5  on 2059  degrees of freedom
    ## AIC: 1702.5
    ## 
    ## Number of Fisher Scoring iterations: 4
    minpH_glm <- glm(in_hospital_death ~ pH_min, data=icu_patients_df1, family="binomial")
    summary(minpH_glm) # is significant
    ## 
    ## Call:
    ## glm(formula = in_hospital_death ~ pH_min, family = "binomial", 
    ##     data = icu_patients_df1)
    ## 
    ## Deviance Residuals: 
    ##     Min       1Q   Median       3Q      Max  
    ## -0.9980  -0.5733  -0.5358  -0.4868   2.2874  
    ## 
    ## Coefficients:
    ##             Estimate Std. Error z value Pr(>|z|)    
    ## (Intercept)  19.5912     4.8996   3.998 6.37e-05 ***
    ## pH_min       -2.9197     0.6699  -4.358 1.31e-05 ***
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## (Dispersion parameter for binomial family taken to be 1)
    ## 
    ##     Null deviance: 1699.7  on 2060  degrees of freedom
    ## Residual deviance: 1677.4  on 2059  degrees of freedom
    ## AIC: 1681.4
    ## 
    ## Number of Fisher Scoring iterations: 4
    maxpH_glm <- glm(in_hospital_death ~ pH_max, data=icu_patients_df1, family="binomial")
    summary(maxpH_glm) # NOT significant
    ## 
    ## Call:
    ## glm(formula = in_hospital_death ~ pH_max, family = "binomial", 
    ##     data = icu_patients_df1)
    ## 
    ## Deviance Residuals: 
    ##     Min       1Q   Median       3Q      Max  
    ## -0.6684  -0.5677  -0.5523  -0.5297   2.0743  
    ## 
    ## Coefficients:
    ##             Estimate Std. Error z value Pr(>|z|)
    ## (Intercept)   9.3001     7.0197   1.325    0.185
    ## pH_max       -1.4944     0.9469  -1.578    0.115
    ## 
    ## (Dispersion parameter for binomial family taken to be 1)
    ## 
    ##     Null deviance: 1699.7  on 2060  degrees of freedom
    ## Residual deviance: 1697.2  on 2059  degrees of freedom
    ## AIC: 1701.2
    ## 
    ## Number of Fisher Scoring iterations: 4
    minRR_glm <- glm(in_hospital_death ~ RespRate_min, data=icu_patients_df1, family="binomial")
    summary(minRR_glm) # is significant
    ## 
    ## Call:
    ## glm(formula = in_hospital_death ~ RespRate_min, family = "binomial", 
    ##     data = icu_patients_df1)
    ## 
    ## Deviance Residuals: 
    ##     Min       1Q   Median       3Q      Max  
    ## -0.7929  -0.5872  -0.5222  -0.4636   2.3445  
    ## 
    ## Coefficients:
    ##              Estimate Std. Error z value Pr(>|z|)    
    ## (Intercept)  -3.01958    0.25802 -11.703  < 2e-16 ***
    ## RespRate_min  0.08432    0.01656   5.091 3.57e-07 ***
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## (Dispersion parameter for binomial family taken to be 1)
    ## 
    ##     Null deviance: 1699.7  on 2060  degrees of freedom
    ## Residual deviance: 1673.6  on 2059  degrees of freedom
    ## AIC: 1677.6
    ## 
    ## Number of Fisher Scoring iterations: 4
    maxRR_glm <- glm(in_hospital_death ~ RespRate_max, data=icu_patients_df1, family="binomial")
    summary(maxRR_glm) # is significant
    ## 
    ## Call:
    ## glm(formula = in_hospital_death ~ RespRate_max, family = "binomial", 
    ##     data = icu_patients_df1)
    ## 
    ## Deviance Residuals: 
    ##     Min       1Q   Median       3Q      Max  
    ## -1.4489  -0.5679  -0.5233  -0.4817   2.1771  
    ## 
    ## Coefficients:
    ##               Estimate Std. Error z value Pr(>|z|)    
    ## (Intercept)  -2.835656   0.235885 -12.021  < 2e-16 ***
    ## RespRate_max  0.035250   0.007412   4.756 1.98e-06 ***
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## (Dispersion parameter for binomial family taken to be 1)
    ## 
    ##     Null deviance: 1699.7  on 2060  degrees of freedom
    ## Residual deviance: 1677.8  on 2059  degrees of freedom
    ## AIC: 1681.8
    ## 
    ## Number of Fisher Scoring iterations: 4
    minTemp_glm <- glm(in_hospital_death ~ Temp_min, data=icu_patients_df1, family="binomial")
    summary(minTemp_glm) # is significant
    ## 
    ## Call:
    ## glm(formula = in_hospital_death ~ Temp_min, family = "binomial", 
    ##     data = icu_patients_df1)
    ## 
    ## Deviance Residuals: 
    ##     Min       1Q   Median       3Q      Max  
    ## -0.8918  -0.5741  -0.5409  -0.4973   2.2040  
    ## 
    ## Coefficients:
    ##             Estimate Std. Error z value Pr(>|z|)    
    ## (Intercept)   7.4599     2.3473   3.178  0.00148 ** 
    ## Temp_min     -0.2571     0.0654  -3.931 8.45e-05 ***
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## (Dispersion parameter for binomial family taken to be 1)
    ## 
    ##     Null deviance: 1699.7  on 2060  degrees of freedom
    ## Residual deviance: 1684.3  on 2059  degrees of freedom
    ## AIC: 1688.3
    ## 
    ## Number of Fisher Scoring iterations: 4
    maxTemp_glm <- glm(in_hospital_death ~ Temp_max, data=icu_patients_df1, family="binomial")
    summary(maxTemp_glm) # NOT significant
    ## 
    ## Call:
    ## glm(formula = in_hospital_death ~ Temp_max, family = "binomial", 
    ##     data = icu_patients_df1)
    ## 
    ## Deviance Residuals: 
    ##     Min       1Q   Median       3Q      Max  
    ## -0.6077  -0.5689  -0.5549  -0.5366   2.1386  
    ## 
    ## Coefficients:
    ##             Estimate Std. Error z value Pr(>|z|)
    ## (Intercept)  1.60419    3.08152   0.521    0.603
    ## Temp_max    -0.08988    0.08183  -1.098    0.272
    ## 
    ## (Dispersion parameter for binomial family taken to be 1)
    ## 
    ##     Null deviance: 1699.7  on 2060  degrees of freedom
    ## Residual deviance: 1698.5  on 2059  degrees of freedom
    ## AIC: 1702.5
    ## 
    ## Number of Fisher Scoring iterations: 4
    maxTropI_glm <- glm(in_hospital_death ~ TroponinI_max, data=icu_patients_df1, family="binomial")
    summary(maxTropI_glm) # NOT significant
    ## 
    ## Call:
    ## glm(formula = in_hospital_death ~ TroponinI_max, family = "binomial", 
    ##     data = icu_patients_df1)
    ## 
    ## Deviance Residuals: 
    ##     Min       1Q   Median       3Q      Max  
    ## -0.5736  -0.5688  -0.5565  -0.5350   2.0415  
    ## 
    ## Coefficients:
    ##                Estimate Std. Error z value Pr(>|z|)    
    ## (Intercept)   -1.719798   0.090789 -18.943   <2e-16 ***
    ## TroponinI_max -0.005329   0.005774  -0.923    0.356    
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## (Dispersion parameter for binomial family taken to be 1)
    ## 
    ##     Null deviance: 1699.7  on 2060  degrees of freedom
    ## Residual deviance: 1698.8  on 2059  degrees of freedom
    ## AIC: 1702.8
    ## 
    ## Number of Fisher Scoring iterations: 4
    maxTropT_glm <- glm(in_hospital_death ~ TroponinT_max, data=icu_patients_df1, family="binomial")
    summary(maxTropT_glm) # is significant
    ## 
    ## Call:
    ## glm(formula = in_hospital_death ~ TroponinT_max, family = "binomial", 
    ##     data = icu_patients_df1)
    ## 
    ## Deviance Residuals: 
    ##     Min       1Q   Median       3Q      Max  
    ## -1.0740  -0.5503  -0.5430  -0.5416   1.9965  
    ## 
    ## Coefficients:
    ##               Estimate Std. Error z value Pr(>|z|)    
    ## (Intercept)   -1.84719    0.06917 -26.705   <2e-16 ***
    ## TroponinT_max  0.06537    0.02638   2.478   0.0132 *  
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## (Dispersion parameter for binomial family taken to be 1)
    ## 
    ##     Null deviance: 1699.7  on 2060  degrees of freedom
    ## Residual deviance: 1694.1  on 2059  degrees of freedom
    ## AIC: 1698.1
    ## 
    ## Number of Fisher Scoring iterations: 4
    minUrine_glm <- glm(in_hospital_death ~ Urine_min, data=icu_patients_df1, family="binomial")
    summary(minUrine_glm) # is significant
    ## 
    ## Call:
    ## glm(formula = in_hospital_death ~ Urine_min, family = "binomial", 
    ##     data = icu_patients_df1)
    ## 
    ## Deviance Residuals: 
    ##     Min       1Q   Median       3Q      Max  
    ## -0.6034  -0.5952  -0.5631  -0.5105   2.9438  
    ## 
    ## Coefficients:
    ##              Estimate Std. Error z value Pr(>|z|)    
    ## (Intercept) -1.610937   0.076052 -21.182  < 2e-16 ***
    ## Urine_min   -0.006020   0.001787  -3.369 0.000756 ***
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## (Dispersion parameter for binomial family taken to be 1)
    ## 
    ##     Null deviance: 1699.7  on 2060  degrees of freedom
    ## Residual deviance: 1683.1  on 2059  degrees of freedom
    ## AIC: 1687.1
    ## 
    ## Number of Fisher Scoring iterations: 5
    minWBC_glm <- glm(in_hospital_death ~ WBC_min, data=icu_patients_df1, family="binomial")
    summary(minWBC_glm) # is significant
    ## 
    ## Call:
    ## glm(formula = in_hospital_death ~ WBC_min, family = "binomial", 
    ##     data = icu_patients_df1)
    ## 
    ## Deviance Residuals: 
    ##     Min       1Q   Median       3Q      Max  
    ## -1.2861  -0.5638  -0.5477  -0.5315   2.0563  
    ## 
    ## Coefficients:
    ##              Estimate Std. Error z value Pr(>|z|)    
    ## (Intercept) -1.987167   0.119356 -16.649   <2e-16 ***
    ## WBC_min      0.017452   0.008437   2.068   0.0386 *  
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## (Dispersion parameter for binomial family taken to be 1)
    ## 
    ##     Null deviance: 1699.7  on 2060  degrees of freedom
    ## Residual deviance: 1695.6  on 2059  degrees of freedom
    ## AIC: 1699.6
    ## 
    ## Number of Fisher Scoring iterations: 4
    maxWBC_glm <- glm(in_hospital_death ~ WBC_max, data=icu_patients_df1, family="binomial")
    summary(maxWBC_glm) # is significant
    ## 
    ## Call:
    ## glm(formula = in_hospital_death ~ WBC_max, family = "binomial", 
    ##     data = icu_patients_df1)
    ## 
    ## Deviance Residuals: 
    ##     Min       1Q   Median       3Q      Max  
    ## -1.2674  -0.5631  -0.5475  -0.5326   2.0545  
    ## 
    ## Coefficients:
    ##              Estimate Std. Error z value Pr(>|z|)    
    ## (Intercept) -1.982652   0.118080 -16.791   <2e-16 ***
    ## WBC_max      0.014086   0.006859   2.054     0.04 *  
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## (Dispersion parameter for binomial family taken to be 1)
    ## 
    ##     Null deviance: 1699.7  on 2060  degrees of freedom
    ## Residual deviance: 1695.7  on 2059  degrees of freedom
    ## AIC: 1699.7
    ## 
    ## Number of Fisher Scoring iterations: 4

    Univariate Models Findings

    • Variables that had a significant Wald test, resulting a rejection of the null hypothesis concluding that the variable is significant in explaining the outcome variable of in_hospital_death are:
      • age
      • ICUType
      • Weight_max
      • Albumin_min
      • Bilirubin_max
      • BUN_max
      • Creatinine_max
      • GCS_min
      • Glucose_max
      • HCO3_min
      • HR_max
      • Lactate_max
      • Na_min
      • NISysABP_min
      • pH_min
      • RespRate_min
      • RespRate_max
      • Temp_min
      • TroponinT_max
      • Urine_min
      • WBC_min
      • WBC_max
    • Variables that resulted in a non-significant Wald test are:
      • Glucose_min
      • HR_min
      • K_min
      • K_max
      • MAP_min
      • Na_max
      • NISysABP_max
      • Platelets_min
      • PFratio
      • pH_max
      • Temp_max
      • TroponinI_max

    Multivariable logistic regression models:

    ## Create a dataset without missing or invalid data to use to build the model ##
    ## in order to remain consistent and allow comparisons between models to be made ##
    
    
    # Check counts of missing data in each variable
    for(i in 1:length(colnames(icu_patients_df1))){
      print(c(i,colnames(icu_patients_df1[i]), sum(is.na(icu_patients_df1[i]))))
    }
    ## [1] "1"        "RecordID" "0"       
    ## [1] "2"              "Length_of_stay" "0"             
    ## [1] "3"     "SAPS1" "96"   
    ## [1] "4"    "SOFA" "0"   
    ## [1] "5"        "Survival" "1288"    
    ## [1] "6"                 "in_hospital_death" "0"                
    ## [1] "7"    "Days" "0"   
    ## [1] "8"      "Status" "0"     
    ## [1] "9"   "Age" "0"  
    ## [1] "10"           "Albumin_diff" "0"           
    ## [1] "11"          "Albumin_max" "0"          
    ## [1] "12"          "Albumin_min" "0"          
    ## [1] "13"       "ALP_diff" "0"       
    ## [1] "14"      "ALP_max" "0"      
    ## [1] "15"      "ALP_min" "0"      
    ## [1] "16"       "ALT_diff" "0"       
    ## [1] "17"      "ALT_max" "0"      
    ## [1] "18"      "ALT_min" "0"      
    ## [1] "19"       "AST_diff" "0"       
    ## [1] "20"      "AST_max" "0"      
    ## [1] "21"      "AST_min" "0"      
    ## [1] "22"             "Bilirubin_diff" "0"             
    ## [1] "23"            "Bilirubin_max" "0"            
    ## [1] "24"            "Bilirubin_min" "0"            
    ## [1] "25"       "BUN_diff" "0"       
    ## [1] "26"      "BUN_max" "0"      
    ## [1] "27"      "BUN_min" "0"      
    ## [1] "28"               "Cholesterol_diff" "0"               
    ## [1] "29"              "Cholesterol_max" "0"              
    ## [1] "30"              "Cholesterol_min" "0"              
    ## [1] "31"              "Creatinine_diff" "0"              
    ## [1] "32"             "Creatinine_max" "0"             
    ## [1] "33"             "Creatinine_min" "0"             
    ## [1] "34"           "DiasABP_diff" "715"         
    ## [1] "35"          "DiasABP_max" "715"        
    ## [1] "36"          "DiasABP_min" "715"        
    ## [1] "37"        "FiO2_diff" "0"        
    ## [1] "38"       "FiO2_max" "0"       
    ## [1] "39"       "FiO2_min" "0"       
    ## [1] "40"       "GCS_diff" "0"       
    ## [1] "41"      "GCS_max" "0"      
    ## [1] "42"      "GCS_min" "0"      
    ## [1] "43"     "Gender" "0"     
    ## [1] "44"           "Glucose_diff" "0"           
    ## [1] "45"          "Glucose_max" "0"          
    ## [1] "46"          "Glucose_min" "0"          
    ## [1] "47"        "HCO3_diff" "0"        
    ## [1] "48"       "HCO3_max" "0"       
    ## [1] "49"       "HCO3_min" "0"       
    ## [1] "50"       "HCT_diff" "0"       
    ## [1] "51"      "HCT_max" "0"      
    ## [1] "52"      "HCT_min" "0"      
    ## [1] "53"     "Height" "992"   
    ## [1] "54"      "HR_diff" "0"      
    ## [1] "55"     "HR_max" "0"     
    ## [1] "56"     "HR_min" "0"     
    ## [1] "57"      "ICUType" "0"      
    ## [1] "58"     "K_diff" "0"     
    ## [1] "59"    "K_max" "0"    
    ## [1] "60"    "K_min" "0"    
    ## [1] "61"           "Lactate_diff" "0"           
    ## [1] "62"          "Lactate_max" "0"          
    ## [1] "63"          "Lactate_min" "0"          
    ## [1] "64"       "MAP_diff" "0"       
    ## [1] "65"      "MAP_max" "0"      
    ## [1] "66"      "MAP_min" "0"      
    ## [1] "67"      "Mg_diff" "0"      
    ## [1] "68"     "Mg_max" "0"     
    ## [1] "69"     "Mg_min" "0"     
    ## [1] "70"      "Na_diff" "0"      
    ## [1] "71"     "Na_max" "0"     
    ## [1] "72"     "Na_min" "0"     
    ## [1] "73"             "NIDiasABP_diff" "455"           
    ## [1] "74"            "NIDiasABP_max" "455"          
    ## [1] "75"            "NIDiasABP_min" "455"          
    ## [1] "76"         "NIMAP_diff" "455"       
    ## [1] "77"        "NIMAP_max" "455"      
    ## [1] "78"        "NIMAP_min" "455"      
    ## [1] "79"            "NISysABP_diff" "453"          
    ## [1] "80"           "NISysABP_max" "453"         
    ## [1] "81"           "NISysABP_min" "453"         
    ## [1] "82"         "PaCO2_diff" "0"         
    ## [1] "83"        "PaCO2_max" "0"        
    ## [1] "84"        "PaCO2_min" "0"        
    ## [1] "85"        "PaO2_diff" "0"        
    ## [1] "86"       "PaO2_max" "0"       
    ## [1] "87"       "PaO2_min" "0"       
    ## [1] "88"      "pH_diff" "0"      
    ## [1] "89"     "pH_max" "0"     
    ## [1] "90"     "pH_min" "0"     
    ## [1] "91"             "Platelets_diff" "0"             
    ## [1] "92"            "Platelets_max" "0"            
    ## [1] "93"            "Platelets_min" "0"            
    ## [1] "94"            "RespRate_diff" "0"            
    ## [1] "95"           "RespRate_max" "0"           
    ## [1] "96"           "RespRate_min" "0"           
    ## [1] "97"        "SaO2_diff" "0"        
    ## [1] "98"       "SaO2_max" "0"       
    ## [1] "99"       "SaO2_min" "0"       
    ## [1] "100"         "SysABP_diff" "715"        
    ## [1] "101"        "SysABP_max" "715"       
    ## [1] "102"        "SysABP_min" "715"       
    ## [1] "103"       "Temp_diff" "0"        
    ## [1] "104"      "Temp_max" "0"       
    ## [1] "105"      "Temp_min" "0"       
    ## [1] "106"            "TroponinI_diff" "0"             
    ## [1] "107"           "TroponinI_max" "0"            
    ## [1] "108"           "TroponinI_min" "0"            
    ## [1] "109"            "TroponinT_diff" "0"             
    ## [1] "110"           "TroponinT_max" "0"            
    ## [1] "111"           "TroponinT_min" "0"            
    ## [1] "112"        "Urine_diff" "0"         
    ## [1] "113"       "Urine_max" "0"        
    ## [1] "114"       "Urine_min" "0"        
    ## [1] "115"      "WBC_diff" "0"       
    ## [1] "116"     "WBC_max" "0"      
    ## [1] "117"     "WBC_min" "0"      
    ## [1] "118"         "Weight_diff" "146"        
    ## [1] "119"        "Weight_max" "146"       
    ## [1] "120"        "Weight_min" "146"       
    ## [1] "121"     "PFratio" "0"
    ## Result: of the variables chosen to explore for the survival model, large amounts of missing data in:
    ##         Height (992), NISysABP_min (453), NISysABP_max (453), Weight_max (146)
    
    ## Decision: include Weight_max; remove Height, NISysABP_min, NISysABP_max
    
    
    # Check counts of negative data (noted some -1 values) in each variable
    for(i in 1:length(colnames(icu_patients_df1))){
      print(c(i,colnames(icu_patients_df1[i]), sum(icu_patients_df1[i] < 0)))
    }
    ## [1] "1"        "RecordID" "0"       
    ## [1] "2"              "Length_of_stay" "25"            
    ## [1] "3"     "SAPS1" NA     
    ## [1] "4"    "SOFA" "65"  
    ## [1] "5"        "Survival" NA        
    ## [1] "6"                 "in_hospital_death" "0"                
    ## [1] "7"    "Days" "0"   
    ## [1] "8"      "Status" "0"     
    ## [1] "9"   "Age" "0"  
    ## [1] "10"           "Albumin_diff" "0"           
    ## [1] "11"          "Albumin_max" "0"          
    ## [1] "12"          "Albumin_min" "0"          
    ## [1] "13"       "ALP_diff" "0"       
    ## [1] "14"      "ALP_max" "0"      
    ## [1] "15"      "ALP_min" "0"      
    ## [1] "16"       "ALT_diff" "0"       
    ## [1] "17"      "ALT_max" "0"      
    ## [1] "18"      "ALT_min" "0"      
    ## [1] "19"       "AST_diff" "0"       
    ## [1] "20"      "AST_max" "0"      
    ## [1] "21"      "AST_min" "0"      
    ## [1] "22"             "Bilirubin_diff" "0"             
    ## [1] "23"            "Bilirubin_max" "0"            
    ## [1] "24"            "Bilirubin_min" "0"            
    ## [1] "25"       "BUN_diff" "0"       
    ## [1] "26"      "BUN_max" "0"      
    ## [1] "27"      "BUN_min" "0"      
    ## [1] "28"               "Cholesterol_diff" "0"               
    ## [1] "29"              "Cholesterol_max" "0"              
    ## [1] "30"              "Cholesterol_min" "0"              
    ## [1] "31"              "Creatinine_diff" "0"              
    ## [1] "32"             "Creatinine_max" "0"             
    ## [1] "33"             "Creatinine_min" "0"             
    ## [1] "34"           "DiasABP_diff" NA            
    ## [1] "35"          "DiasABP_max" NA           
    ## [1] "36"          "DiasABP_min" NA           
    ## [1] "37"        "FiO2_diff" "0"        
    ## [1] "38"       "FiO2_max" "0"       
    ## [1] "39"       "FiO2_min" "0"       
    ## [1] "40"       "GCS_diff" "0"       
    ## [1] "41"      "GCS_max" "0"      
    ## [1] "42"      "GCS_min" "0"
    ## Warning in Ops.factor(left, right): '<' not meaningful for factors
    ## [1] "43"     "Gender" NA      
    ## [1] "44"           "Glucose_diff" "0"           
    ## [1] "45"          "Glucose_max" "0"          
    ## [1] "46"          "Glucose_min" "0"          
    ## [1] "47"        "HCO3_diff" "0"        
    ## [1] "48"       "HCO3_max" "0"       
    ## [1] "49"       "HCO3_min" "0"       
    ## [1] "50"       "HCT_diff" "0"       
    ## [1] "51"      "HCT_max" "0"      
    ## [1] "52"      "HCT_min" "0"      
    ## [1] "53"     "Height" NA      
    ## [1] "54"      "HR_diff" "0"      
    ## [1] "55"     "HR_max" "0"     
    ## [1] "56"     "HR_min" "0"
    ## Warning in Ops.factor(left, right): '<' not meaningful for factors
    ## [1] "57"      "ICUType" NA       
    ## [1] "58"     "K_diff" "0"     
    ## [1] "59"    "K_max" "0"    
    ## [1] "60"    "K_min" "0"    
    ## [1] "61"           "Lactate_diff" "0"           
    ## [1] "62"          "Lactate_max" "0"          
    ## [1] "63"          "Lactate_min" "0"          
    ## [1] "64"       "MAP_diff" "0"       
    ## [1] "65"      "MAP_max" "0"      
    ## [1] "66"      "MAP_min" "0"      
    ## [1] "67"      "Mg_diff" "0"      
    ## [1] "68"     "Mg_max" "0"     
    ## [1] "69"     "Mg_min" "0"     
    ## [1] "70"      "Na_diff" "0"      
    ## [1] "71"     "Na_max" "0"     
    ## [1] "72"     "Na_min" "0"     
    ## [1] "73"             "NIDiasABP_diff" NA              
    ## [1] "74"            "NIDiasABP_max" NA             
    ## [1] "75"            "NIDiasABP_min" NA             
    ## [1] "76"         "NIMAP_diff" NA          
    ## [1] "77"        "NIMAP_max" NA         
    ## [1] "78"        "NIMAP_min" NA         
    ## [1] "79"            "NISysABP_diff" NA             
    ## [1] "80"           "NISysABP_max" NA            
    ## [1] "81"           "NISysABP_min" NA            
    ## [1] "82"         "PaCO2_diff" "0"         
    ## [1] "83"        "PaCO2_max" "0"        
    ## [1] "84"        "PaCO2_min" "0"        
    ## [1] "85"        "PaO2_diff" "0"        
    ## [1] "86"       "PaO2_max" "0"       
    ## [1] "87"       "PaO2_min" "0"       
    ## [1] "88"      "pH_diff" "0"      
    ## [1] "89"     "pH_max" "0"     
    ## [1] "90"     "pH_min" "0"     
    ## [1] "91"             "Platelets_diff" "0"             
    ## [1] "92"            "Platelets_max" "0"            
    ## [1] "93"            "Platelets_min" "0"            
    ## [1] "94"            "RespRate_diff" "0"            
    ## [1] "95"           "RespRate_max" "0"           
    ## [1] "96"           "RespRate_min" "0"           
    ## [1] "97"        "SaO2_diff" "0"        
    ## [1] "98"       "SaO2_max" "0"       
    ## [1] "99"       "SaO2_min" "0"       
    ## [1] "100"         "SysABP_diff" NA           
    ## [1] "101"        "SysABP_max" NA          
    ## [1] "102"        "SysABP_min" NA          
    ## [1] "103"       "Temp_diff" "0"        
    ## [1] "104"      "Temp_max" "0"       
    ## [1] "105"      "Temp_min" "0"       
    ## [1] "106"            "TroponinI_diff" "0"             
    ## [1] "107"           "TroponinI_max" "0"            
    ## [1] "108"           "TroponinI_min" "0"            
    ## [1] "109"            "TroponinT_diff" "0"             
    ## [1] "110"           "TroponinT_max" "0"            
    ## [1] "111"           "TroponinT_min" "0"            
    ## [1] "112"        "Urine_diff" "0"         
    ## [1] "113"       "Urine_max" "0"        
    ## [1] "114"       "Urine_min" "0"        
    ## [1] "115"      "WBC_diff" "0"       
    ## [1] "116"     "WBC_max" "0"      
    ## [1] "117"     "WBC_min" "0"      
    ## [1] "118"         "Weight_diff" NA           
    ## [1] "119"        "Weight_max" NA          
    ## [1] "120"        "Weight_min" NA          
    ## [1] "121"     "PFratio" "0"
    ## Result: negative values in Length_of_stay and SOFA (not listed in initial choice of variables anyway)
    
    # Create a new dataset with the only non-missing data from list of initial variables chosen
    # (excluding those with very high missingness i.e. Height, NISysABP_min, NISysABP_max)
    nm_icu_model_df1 <- na.omit(subset(icu_patients_df1, 
                                       select=c(Days, Status, # the survival object variables (for task 2)
                                                RecordID, # keep record id for reference if needed
                                                in_hospital_death, # for task 1
                                                Age, Gender, ICUType, Weight_max,
                                                Albumin_min, Bilirubin_max,
                                                BUN_max, Creatinine_max, 
                                                GCS_max, Glucose_min, Glucose_max, 
                                                HCO3_min, HR_min, HR_max, K_min, 
                                                K_max, Lactate_max, MAP_min, Na_min,
                                                Na_max, Platelets_min, PFratio, pH_min,
                                                pH_max, RespRate_min, RespRate_max,
                                                Temp_min, Temp_max, TroponinT_max, 
                                                TroponinI_max, Urine_min, WBC_min, WBC_max)))
    
    
    # all variables from initially selected predictors
    full_glm <- glm(in_hospital_death ~ 
                      Age + 
                      Gender + 
                      ICUType + 
                      Weight_max +
                      Albumin_min +
                      Bilirubin_max + 
                      BUN_max + 
                      Creatinine_max + 
                      GCS_max + 
                      Glucose_min + 
                      Glucose_max + 
                      HCO3_min +
                      HR_min + 
                      HR_max + 
                      K_min + 
                      K_max + 
                      Lactate_max + 
                      MAP_min + 
                      Na_min +
                      Na_max +
                      Platelets_min +
                      PFratio +
                      pH_min +
                      pH_max +
                      RespRate_min +
                      RespRate_max + 
                      Temp_min + 
                      Temp_max +
                      TroponinT_max +
                      TroponinI_max + 
                      Urine_min + 
                      WBC_min + 
                      WBC_max
                    ,data=nm_icu_model_df1, family="binomial")
    summary(full_glm) #AIC 1332.1
    ## 
    ## Call:
    ## glm(formula = in_hospital_death ~ Age + Gender + ICUType + Weight_max + 
    ##     Albumin_min + Bilirubin_max + BUN_max + Creatinine_max + 
    ##     GCS_max + Glucose_min + Glucose_max + HCO3_min + HR_min + 
    ##     HR_max + K_min + K_max + Lactate_max + MAP_min + Na_min + 
    ##     Na_max + Platelets_min + PFratio + pH_min + pH_max + RespRate_min + 
    ##     RespRate_max + Temp_min + Temp_max + TroponinT_max + TroponinI_max + 
    ##     Urine_min + WBC_min + WBC_max, family = "binomial", data = nm_icu_model_df1)
    ## 
    ## Deviance Residuals: 
    ##     Min       1Q   Median       3Q      Max  
    ## -2.0025  -0.5414  -0.3387  -0.1826   3.1551  
    ## 
    ## Coefficients:
    ##                                        Estimate Std. Error z value Pr(>|z|)    
    ## (Intercept)                          24.7550693 11.0324370   2.244 0.024842 *  
    ## Age                                   0.0355727  0.0055679   6.389 1.67e-10 ***
    ## GenderMale                           -0.0005774  0.1586626  -0.004 0.997097    
    ## ICUTypeCardiac Surgery Recovery Unit -1.1946684  0.3314631  -3.604 0.000313 ***
    ## ICUTypeMedical ICU                    0.1457551  0.2305142   0.632 0.527188    
    ## ICUTypeSurgical ICU                   0.1776610  0.2563794   0.693 0.488334    
    ## Weight_max                           -0.0041882  0.0037136  -1.128 0.259409    
    ## Albumin_min                          -0.3103087  0.1269198  -2.445 0.014488 *  
    ## Bilirubin_max                         0.0397973  0.0145689   2.732 0.006301 ** 
    ## BUN_max                               0.0218067  0.0041617   5.240 1.61e-07 ***
    ## Creatinine_max                       -0.0512660  0.0566167  -0.905 0.365204    
    ## GCS_max                              -0.1896782  0.0267396  -7.094 1.31e-12 ***
    ## Glucose_min                           0.0004277  0.0017341   0.247 0.805197    
    ## Glucose_max                           0.0005729  0.0010105   0.567 0.570710    
    ## HCO3_min                              0.0094985  0.0185570   0.512 0.608753    
    ## HR_min                                0.0110264  0.0057790   1.908 0.056391 .  
    ## HR_max                                0.0046164  0.0038442   1.201 0.229792    
    ## K_min                                -0.0801749  0.1621385  -0.494 0.620964    
    ## K_max                                -0.0707587  0.1016629  -0.696 0.486420    
    ## Lactate_max                           0.0645205  0.0365291   1.766 0.077350 .  
    ## MAP_min                              -0.0001513  0.0044240  -0.034 0.972727    
    ## Na_min                                0.0041071  0.0353159   0.116 0.907418    
    ## Na_max                               -0.0648695  0.0356990  -1.817 0.069198 .  
    ## Platelets_min                        -0.0009868  0.0008076  -1.222 0.221726    
    ## PFratio                              -0.0001635  0.0007894  -0.207 0.835900    
    ## pH_min                               -1.2268398  0.9477985  -1.294 0.195524    
    ## pH_max                               -0.1918512  1.4140768  -0.136 0.892080    
    ## RespRate_min                         -0.0231207  0.0254338  -0.909 0.363322    
    ## RespRate_max                          0.0138618  0.0122981   1.127 0.259680    
    ## Temp_min                             -0.1907196  0.0883748  -2.158 0.030922 *  
    ## Temp_max                             -0.0308143  0.1062282  -0.290 0.771758    
    ## TroponinT_max                         0.0188442  0.0354984   0.531 0.595525    
    ## TroponinI_max                        -0.0028271  0.0078796  -0.359 0.719758    
    ## Urine_min                            -0.0063152  0.0026190  -2.411 0.015897 *  
    ## WBC_min                               0.0656428  0.0277205   2.368 0.017883 *  
    ## WBC_max                              -0.0521569  0.0229737  -2.270 0.023190 *  
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## (Dispersion parameter for binomial family taken to be 1)
    ## 
    ##     Null deviance: 1604.2  on 1914  degrees of freedom
    ## Residual deviance: 1260.1  on 1879  degrees of freedom
    ## AIC: 1332.1
    ## 
    ## Number of Fisher Scoring iterations: 6
    ###
    # variables that were significant on univariate comparisons
    signifUni_glm <- glm(in_hospital_death ~
                           Age + 
                           ICUType + 
                           Weight_max +
                           Albumin_min + 
                           Bilirubin_max + 
                           BUN_max + 
                           Creatinine_max +
                           GCS_max + 
                           Glucose_max + 
                           HCO3_min + 
                           HR_max +
                           Lactate_max +
                           Na_min +
                           # NISysABP_min + this was removed from the na.omit part anyway
                           pH_min + 
                           RespRate_min +
                           RespRate_max +
                           Temp_min + 
                           TroponinT_max +
                           Urine_min +
                           WBC_min +
                           WBC_max
                         ,data=nm_icu_model_df1, family="binomial")
    summary(signifUni_glm) #AIC 1320.9
    ## 
    ## Call:
    ## glm(formula = in_hospital_death ~ Age + ICUType + Weight_max + 
    ##     Albumin_min + Bilirubin_max + BUN_max + Creatinine_max + 
    ##     GCS_max + Glucose_max + HCO3_min + HR_max + Lactate_max + 
    ##     Na_min + pH_min + RespRate_min + RespRate_max + Temp_min + 
    ##     TroponinT_max + Urine_min + WBC_min + WBC_max, family = "binomial", 
    ##     data = nm_icu_model_df1)
    ## 
    ## Deviance Residuals: 
    ##     Min       1Q   Median       3Q      Max  
    ## -1.9897  -0.5398  -0.3458  -0.1906   3.0306  
    ## 
    ## Coefficients:
    ##                                        Estimate Std. Error z value Pr(>|z|)    
    ## (Intercept)                           1.799e+01  6.567e+00   2.739 0.006157 ** 
    ## Age                                   3.404e-02  5.318e-03   6.401 1.55e-10 ***
    ## ICUTypeCardiac Surgery Recovery Unit -1.087e+00  3.073e-01  -3.538 0.000403 ***
    ## ICUTypeMedical ICU                    1.537e-01  2.259e-01   0.680 0.496226    
    ## ICUTypeSurgical ICU                   1.585e-01  2.470e-01   0.642 0.521184    
    ## Weight_max                           -3.417e-03  3.473e-03  -0.984 0.325245    
    ## Albumin_min                          -3.454e-01  1.223e-01  -2.824 0.004737 ** 
    ## Bilirubin_max                         4.376e-02  1.403e-02   3.120 0.001811 ** 
    ## BUN_max                               2.101e-02  3.916e-03   5.365 8.10e-08 ***
    ## Creatinine_max                       -6.020e-02  5.508e-02  -1.093 0.274450    
    ## GCS_max                              -1.781e-01  2.490e-02  -7.155 8.39e-13 ***
    ## Glucose_max                          -6.786e-07  7.610e-04  -0.001 0.999288    
    ## HCO3_min                              6.078e-03  1.765e-02   0.344 0.730494    
    ## HR_max                                7.162e-03  3.308e-03   2.165 0.030393 *  
    ## Lactate_max                           6.304e-02  3.494e-02   1.804 0.071235 .  
    ## Na_min                               -4.359e-02  1.467e-02  -2.972 0.002959 ** 
    ## pH_min                               -1.172e+00  8.056e-01  -1.455 0.145582    
    ## RespRate_min                         -1.761e-02  2.465e-02  -0.715 0.474870    
    ## RespRate_max                          1.419e-02  1.103e-02   1.287 0.198258    
    ## Temp_min                             -1.578e-01  7.993e-02  -1.974 0.048379 *  
    ## TroponinT_max                         1.198e-02  3.453e-02   0.347 0.728694    
    ## Urine_min                            -6.348e-03  2.574e-03  -2.467 0.013643 *  
    ## WBC_min                               6.828e-02  2.601e-02   2.625 0.008672 ** 
    ## WBC_max                              -6.037e-02  2.207e-02  -2.736 0.006225 ** 
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## (Dispersion parameter for binomial family taken to be 1)
    ## 
    ##     Null deviance: 1604.2  on 1914  degrees of freedom
    ## Residual deviance: 1272.9  on 1891  degrees of freedom
    ## AIC: 1320.9
    ## 
    ## Number of Fisher Scoring iterations: 6
    ###
    # variables that were significant in the full_glm
    signifFull_glm <- glm(in_hospital_death ~
                            Age + 
                            ICUType +
                            Albumin_min + 
                            Bilirubin_max + 
                            BUN_max + 
                            GCS_max + 
                            Temp_min + 
                            Urine_min + 
                            WBC_min + 
                            WBC_max
                          ,data=nm_icu_model_df1, family="binomial")
    summary(signifFull_glm) #AIC 1330.2
    ## 
    ## Call:
    ## glm(formula = in_hospital_death ~ Age + ICUType + Albumin_min + 
    ##     Bilirubin_max + BUN_max + GCS_max + Temp_min + Urine_min + 
    ##     WBC_min + WBC_max, family = "binomial", data = nm_icu_model_df1)
    ## 
    ## Deviance Residuals: 
    ##     Min       1Q   Median       3Q      Max  
    ## -1.8919  -0.5497  -0.3649  -0.2046   3.0349  
    ## 
    ## Coefficients:
    ##                                       Estimate Std. Error z value Pr(>|z|)    
    ## (Intercept)                           6.356911   2.698679   2.356  0.01849 *  
    ## Age                                   0.030984   0.004850   6.389 1.67e-10 ***
    ## ICUTypeCardiac Surgery Recovery Unit -1.206231   0.286775  -4.206 2.60e-05 ***
    ## ICUTypeMedical ICU                    0.065555   0.210415   0.312  0.75538    
    ## ICUTypeSurgical ICU                  -0.033654   0.229228  -0.147  0.88328    
    ## Albumin_min                          -0.380485   0.118054  -3.223  0.00127 ** 
    ## Bilirubin_max                         0.054089   0.013137   4.117 3.83e-05 ***
    ## BUN_max                               0.017585   0.002832   6.209 5.34e-10 ***
    ## GCS_max                              -0.179975   0.020954  -8.589  < 2e-16 ***
    ## Temp_min                             -0.201811   0.073755  -2.736  0.00621 ** 
    ## Urine_min                            -0.007162   0.002585  -2.770  0.00560 ** 
    ## WBC_min                               0.055865   0.024568   2.274  0.02297 *  
    ## WBC_max                              -0.044776   0.020492  -2.185  0.02889 *  
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## (Dispersion parameter for binomial family taken to be 1)
    ## 
    ##     Null deviance: 1604.2  on 1914  degrees of freedom
    ## Residual deviance: 1304.2  on 1902  degrees of freedom
    ## AIC: 1330.2
    ## 
    ## Number of Fisher Scoring iterations: 6
    # no missing data removed due to missingness
    
    # anova doesn't work because different missing data between the models
    anova(full_glm, signifUni_glm, test="Chisq") # the parameters different between the models are not significant
    ## Analysis of Deviance Table
    ## 
    ## Model 1: in_hospital_death ~ Age + Gender + ICUType + Weight_max + Albumin_min + 
    ##     Bilirubin_max + BUN_max + Creatinine_max + GCS_max + Glucose_min + 
    ##     Glucose_max + HCO3_min + HR_min + HR_max + K_min + K_max + 
    ##     Lactate_max + MAP_min + Na_min + Na_max + Platelets_min + 
    ##     PFratio + pH_min + pH_max + RespRate_min + RespRate_max + 
    ##     Temp_min + Temp_max + TroponinT_max + TroponinI_max + Urine_min + 
    ##     WBC_min + WBC_max
    ## Model 2: in_hospital_death ~ Age + ICUType + Weight_max + Albumin_min + 
    ##     Bilirubin_max + BUN_max + Creatinine_max + GCS_max + Glucose_max + 
    ##     HCO3_min + HR_max + Lactate_max + Na_min + pH_min + RespRate_min + 
    ##     RespRate_max + Temp_min + TroponinT_max + Urine_min + WBC_min + 
    ##     WBC_max
    ##   Resid. Df Resid. Dev  Df Deviance Pr(>Chi)
    ## 1      1879     1260.1                      
    ## 2      1891     1272.9 -12  -12.783    0.385
    anova(full_glm, signifFull_glm, test="Chisq") # the dropped parameters between the two models do matter
    ## Analysis of Deviance Table
    ## 
    ## Model 1: in_hospital_death ~ Age + Gender + ICUType + Weight_max + Albumin_min + 
    ##     Bilirubin_max + BUN_max + Creatinine_max + GCS_max + Glucose_min + 
    ##     Glucose_max + HCO3_min + HR_min + HR_max + K_min + K_max + 
    ##     Lactate_max + MAP_min + Na_min + Na_max + Platelets_min + 
    ##     PFratio + pH_min + pH_max + RespRate_min + RespRate_max + 
    ##     Temp_min + Temp_max + TroponinT_max + TroponinI_max + Urine_min + 
    ##     WBC_min + WBC_max
    ## Model 2: in_hospital_death ~ Age + ICUType + Albumin_min + Bilirubin_max + 
    ##     BUN_max + GCS_max + Temp_min + Urine_min + WBC_min + WBC_max
    ##   Resid. Df Resid. Dev  Df Deviance Pr(>Chi)   
    ## 1      1879     1260.1                         
    ## 2      1902     1304.2 -23  -44.154 0.005039 **
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ###
    # using the model with the lowest AIC
    # reduce it even further
    reduced_signifUni_glm <- step(signifUni_glm, trace=1)
    ## Start:  AIC=1320.87
    ## in_hospital_death ~ Age + ICUType + Weight_max + Albumin_min + 
    ##     Bilirubin_max + BUN_max + Creatinine_max + GCS_max + Glucose_max + 
    ##     HCO3_min + HR_max + Lactate_max + Na_min + pH_min + RespRate_min + 
    ##     RespRate_max + Temp_min + TroponinT_max + Urine_min + WBC_min + 
    ##     WBC_max
    ## 
    ##                  Df Deviance    AIC
    ## - Glucose_max     1   1272.9 1318.9
    ## - HCO3_min        1   1273.0 1319.0
    ## - TroponinT_max   1   1273.0 1319.0
    ## - RespRate_min    1   1273.4 1319.4
    ## - Weight_max      1   1273.9 1319.9
    ## - Creatinine_max  1   1274.1 1320.1
    ## - RespRate_max    1   1274.5 1320.5
    ## <none>                1272.9 1320.9
    ## - Lactate_max     1   1276.1 1322.1
    ## - pH_min          1   1276.6 1322.6
    ## - Temp_min        1   1276.9 1322.9
    ## - HR_max          1   1277.5 1323.5
    ## - WBC_min         1   1280.1 1326.1
    ## - Urine_min       1   1280.9 1326.9
    ## - WBC_max         1   1280.9 1326.9
    ## - Albumin_min     1   1280.9 1326.9
    ## - Na_min          1   1281.6 1327.6
    ## - Bilirubin_max   1   1282.3 1328.3
    ## - ICUType         3   1302.5 1344.5
    ## - BUN_max         1   1302.5 1348.5
    ## - Age             1   1318.7 1364.7
    ## - GCS_max         1   1325.1 1371.1
    ## 
    ## Step:  AIC=1318.87
    ## in_hospital_death ~ Age + ICUType + Weight_max + Albumin_min + 
    ##     Bilirubin_max + BUN_max + Creatinine_max + GCS_max + HCO3_min + 
    ##     HR_max + Lactate_max + Na_min + pH_min + RespRate_min + RespRate_max + 
    ##     Temp_min + TroponinT_max + Urine_min + WBC_min + WBC_max
    ## 
    ##                  Df Deviance    AIC
    ## - TroponinT_max   1   1273.0 1317.0
    ## - HCO3_min        1   1273.0 1317.0
    ## - RespRate_min    1   1273.4 1317.4
    ## - Weight_max      1   1273.9 1317.9
    ## - Creatinine_max  1   1274.1 1318.1
    ## - RespRate_max    1   1274.5 1318.5
    ## <none>                1272.9 1318.9
    ## - Lactate_max     1   1276.2 1320.2
    ## - pH_min          1   1276.6 1320.6
    ## - Temp_min        1   1276.9 1320.9
    ## - HR_max          1   1277.5 1321.5
    ## - WBC_min         1   1280.1 1324.1
    ## - Urine_min       1   1280.9 1324.9
    ## - WBC_max         1   1280.9 1324.9
    ## - Albumin_min     1   1281.0 1325.0
    ## - Na_min          1   1281.7 1325.7
    ## - Bilirubin_max   1   1282.4 1326.4
    ## - ICUType         3   1303.2 1343.2
    ## - BUN_max         1   1302.6 1346.6
    ## - Age             1   1318.8 1362.8
    ## - GCS_max         1   1325.3 1369.3
    ## 
    ## Step:  AIC=1316.99
    ## in_hospital_death ~ Age + ICUType + Weight_max + Albumin_min + 
    ##     Bilirubin_max + BUN_max + Creatinine_max + GCS_max + HCO3_min + 
    ##     HR_max + Lactate_max + Na_min + pH_min + RespRate_min + RespRate_max + 
    ##     Temp_min + Urine_min + WBC_min + WBC_max
    ## 
    ##                  Df Deviance    AIC
    ## - HCO3_min        1   1273.1 1315.1
    ## - RespRate_min    1   1273.5 1315.5
    ## - Weight_max      1   1274.0 1316.0
    ## - Creatinine_max  1   1274.2 1316.2
    ## - RespRate_max    1   1274.7 1316.7
    ## <none>                1273.0 1317.0
    ## - Lactate_max     1   1276.7 1318.7
    ## - Temp_min        1   1277.0 1319.0
    ## - pH_min          1   1277.1 1319.1
    ## - HR_max          1   1277.5 1319.5
    ## - WBC_min         1   1280.6 1322.6
    ## - Urine_min       1   1281.0 1323.0
    ## - Albumin_min     1   1281.2 1323.2
    ## - WBC_max         1   1281.4 1323.4
    ## - Na_min          1   1282.0 1324.0
    ## - Bilirubin_max   1   1282.9 1324.9
    ## - ICUType         3   1303.3 1341.3
    ## - BUN_max         1   1302.7 1344.7
    ## - Age             1   1318.8 1360.8
    ## - GCS_max         1   1325.5 1367.5
    ## 
    ## Step:  AIC=1315.11
    ## in_hospital_death ~ Age + ICUType + Weight_max + Albumin_min + 
    ##     Bilirubin_max + BUN_max + Creatinine_max + GCS_max + HR_max + 
    ##     Lactate_max + Na_min + pH_min + RespRate_min + RespRate_max + 
    ##     Temp_min + Urine_min + WBC_min + WBC_max
    ## 
    ##                  Df Deviance    AIC
    ## - RespRate_min    1   1273.6 1313.6
    ## - Weight_max      1   1274.1 1314.1
    ## - Creatinine_max  1   1274.4 1314.4
    ## - RespRate_max    1   1274.8 1314.8
    ## <none>                1273.1 1315.1
    ## - Lactate_max     1   1276.7 1316.7
    ## - Temp_min        1   1277.0 1317.0
    ## - pH_min          1   1277.1 1317.1
    ## - HR_max          1   1277.6 1317.6
    ## - WBC_min         1   1280.9 1320.9
    ## - Urine_min       1   1281.1 1321.1
    ## - Albumin_min     1   1281.2 1321.2
    ## - WBC_max         1   1281.9 1321.9
    ## - Na_min          1   1282.0 1322.0
    ## - Bilirubin_max   1   1283.2 1323.2
    ## - ICUType         3   1303.3 1339.3
    ## - BUN_max         1   1302.7 1342.7
    ## - Age             1   1319.3 1359.3
    ## - GCS_max         1   1325.5 1365.5
    ## 
    ## Step:  AIC=1313.62
    ## in_hospital_death ~ Age + ICUType + Weight_max + Albumin_min + 
    ##     Bilirubin_max + BUN_max + Creatinine_max + GCS_max + HR_max + 
    ##     Lactate_max + Na_min + pH_min + RespRate_max + Temp_min + 
    ##     Urine_min + WBC_min + WBC_max
    ## 
    ##                  Df Deviance    AIC
    ## - Weight_max      1   1274.6 1312.6
    ## - RespRate_max    1   1274.8 1312.8
    ## - Creatinine_max  1   1274.9 1312.9
    ## <none>                1273.6 1313.6
    ## - Lactate_max     1   1277.3 1315.3
    ## - pH_min          1   1277.4 1315.4
    ## - Temp_min        1   1277.7 1315.7
    ## - HR_max          1   1277.9 1315.9
    ## - Albumin_min     1   1281.5 1319.5
    ## - Urine_min       1   1281.6 1319.6
    ## - WBC_min         1   1281.8 1319.8
    ## - Na_min          1   1282.3 1320.3
    ## - WBC_max         1   1283.0 1321.0
    ## - Bilirubin_max   1   1284.3 1322.3
    ## - ICUType         3   1303.4 1337.4
    ## - BUN_max         1   1303.3 1341.3
    ## - Age             1   1319.3 1357.3
    ## - GCS_max         1   1329.8 1367.8
    ## 
    ## Step:  AIC=1312.62
    ## in_hospital_death ~ Age + ICUType + Albumin_min + Bilirubin_max + 
    ##     BUN_max + Creatinine_max + GCS_max + HR_max + Lactate_max + 
    ##     Na_min + pH_min + RespRate_max + Temp_min + Urine_min + WBC_min + 
    ##     WBC_max
    ## 
    ##                  Df Deviance    AIC
    ## - RespRate_max    1   1275.8 1311.8
    ## - Creatinine_max  1   1276.1 1312.1
    ## <none>                1274.6 1312.6
    ## - pH_min          1   1278.2 1314.2
    ## - Lactate_max     1   1278.3 1314.3
    ## - HR_max          1   1279.2 1315.2
    ## - Temp_min        1   1279.5 1315.5
    ## - Albumin_min     1   1282.3 1318.3
    ## - Urine_min       1   1282.7 1318.7
    ## - WBC_min         1   1282.8 1318.8
    ## - Na_min          1   1283.2 1319.2
    ## - WBC_max         1   1284.2 1320.2
    ## - Bilirubin_max   1   1285.2 1321.2
    ## - ICUType         3   1306.4 1338.4
    ## - BUN_max         1   1303.7 1339.7
    ## - Age             1   1326.6 1362.6
    ## - GCS_max         1   1330.3 1366.3
    ## 
    ## Step:  AIC=1311.85
    ## in_hospital_death ~ Age + ICUType + Albumin_min + Bilirubin_max + 
    ##     BUN_max + Creatinine_max + GCS_max + HR_max + Lactate_max + 
    ##     Na_min + pH_min + Temp_min + Urine_min + WBC_min + WBC_max
    ## 
    ##                  Df Deviance    AIC
    ## - Creatinine_max  1   1277.1 1311.1
    ## <none>                1275.8 1311.8
    ## - Lactate_max     1   1279.5 1313.5
    ## - pH_min          1   1279.6 1313.6
    ## - Temp_min        1   1280.3 1314.3
    ## - HR_max          1   1281.4 1315.4
    ## - Albumin_min     1   1283.1 1317.1
    ## - Na_min          1   1283.8 1317.8
    ## - Urine_min       1   1284.0 1318.0
    ## - WBC_min         1   1284.0 1318.0
    ## - WBC_max         1   1285.0 1319.0
    ## - Bilirubin_max   1   1288.6 1322.6
    ## - ICUType         3   1307.0 1337.0
    ## - BUN_max         1   1304.6 1338.6
    ## - Age             1   1327.0 1361.0
    ## - GCS_max         1   1342.9 1376.9
    ## 
    ## Step:  AIC=1311.11
    ## in_hospital_death ~ Age + ICUType + Albumin_min + Bilirubin_max + 
    ##     BUN_max + GCS_max + HR_max + Lactate_max + Na_min + pH_min + 
    ##     Temp_min + Urine_min + WBC_min + WBC_max
    ## 
    ##                 Df Deviance    AIC
    ## <none>               1277.1 1311.1
    ## - Lactate_max    1   1280.7 1312.7
    ## - pH_min         1   1280.8 1312.8
    ## - Temp_min       1   1281.5 1313.5
    ## - HR_max         1   1282.9 1314.9
    ## - Na_min         1   1284.5 1316.5
    ## - Urine_min      1   1284.7 1316.7
    ## - Albumin_min    1   1284.8 1316.8
    ## - WBC_min        1   1285.6 1317.6
    ## - WBC_max        1   1286.6 1318.6
    ## - Bilirubin_max  1   1289.6 1321.6
    ## - ICUType        3   1308.6 1336.6
    ## - BUN_max        1   1314.1 1346.1
    ## - Age            1   1333.1 1365.1
    ## - GCS_max        1   1344.1 1376.1
    # removed variables were:
      # Glucose_max
      # TroponinT_max
      # HCO3_min
      # RespRate_min
      # Weight_max
      # RespRate_max
      # Creatinine_max
    summary(reduced_signifUni_glm) # AIC 1311.1
    ## 
    ## Call:
    ## glm(formula = in_hospital_death ~ Age + ICUType + Albumin_min + 
    ##     Bilirubin_max + BUN_max + GCS_max + HR_max + Lactate_max + 
    ##     Na_min + pH_min + Temp_min + Urine_min + WBC_min + WBC_max, 
    ##     family = "binomial", data = nm_icu_model_df1)
    ## 
    ## Deviance Residuals: 
    ##     Min       1Q   Median       3Q      Max  
    ## -1.9438  -0.5450  -0.3479  -0.1945   2.9904  
    ## 
    ## Coefficients:
    ##                                       Estimate Std. Error z value Pr(>|z|)    
    ## (Intercept)                          16.771564   6.180202   2.714  0.00665 ** 
    ## Age                                   0.035748   0.005082   7.034 2.01e-12 ***
    ## ICUTypeCardiac Surgery Recovery Unit -1.107288   0.292041  -3.792  0.00015 ***
    ## ICUTypeMedical ICU                    0.138003   0.215368   0.641  0.52167    
    ## ICUTypeSurgical ICU                   0.123606   0.235752   0.524  0.60007    
    ## Albumin_min                          -0.330533   0.119828  -2.758  0.00581 ** 
    ## Bilirubin_max                         0.048073   0.013358   3.599  0.00032 ***
    ## BUN_max                               0.017653   0.002894   6.101 1.06e-09 ***
    ## GCS_max                              -0.177828   0.021643  -8.217  < 2e-16 ***
    ## HR_max                                0.007771   0.003215   2.417  0.01564 *  
    ## Lactate_max                           0.062615   0.033026   1.896  0.05797 .  
    ## Na_min                               -0.038723   0.014114  -2.744  0.00608 ** 
    ## pH_min                               -1.101299   0.756621  -1.456  0.14552    
    ## Temp_min                             -0.162389   0.078329  -2.073  0.03816 *  
    ## Urine_min                            -0.006031   0.002509  -2.404  0.01622 *  
    ## WBC_min                               0.072729   0.025587   2.842  0.00448 ** 
    ## WBC_max                              -0.063857   0.021592  -2.957  0.00310 ** 
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## (Dispersion parameter for binomial family taken to be 1)
    ## 
    ##     Null deviance: 1604.2  on 1914  degrees of freedom
    ## Residual deviance: 1277.1  on 1898  degrees of freedom
    ## AIC: 1311.1
    ## 
    ## Number of Fisher Scoring iterations: 6
    anova(reduced_signifUni_glm,signifUni_glm, test="Chisq") 
    ## Analysis of Deviance Table
    ## 
    ## Model 1: in_hospital_death ~ Age + ICUType + Albumin_min + Bilirubin_max + 
    ##     BUN_max + GCS_max + HR_max + Lactate_max + Na_min + pH_min + 
    ##     Temp_min + Urine_min + WBC_min + WBC_max
    ## Model 2: in_hospital_death ~ Age + ICUType + Weight_max + Albumin_min + 
    ##     Bilirubin_max + BUN_max + Creatinine_max + GCS_max + Glucose_max + 
    ##     HCO3_min + HR_max + Lactate_max + Na_min + pH_min + RespRate_min + 
    ##     RespRate_max + Temp_min + TroponinT_max + Urine_min + WBC_min + 
    ##     WBC_max
    ##   Resid. Df Resid. Dev Df Deviance Pr(>Chi)
    ## 1      1898     1277.1                     
    ## 2      1891     1272.9  7   4.2406   0.7517
    # p value not significant, the dropped parameters are not significant

    commentary to explain developing the models above

    Final multivariable logistic regression model:

    # same as model above: reduced_signifUni_glm
    finalICU_glm <- glm(in_hospital_death ~ 
                          Age +
                          ICUType + 
                          Albumin_min + 
                          Bilirubin_max +
                          BUN_max + 
                          GCS_max + 
                          HR_max + 
                          Lactate_max + 
                          Na_min + 
                          pH_min + 
                          Temp_min + 
                          Urine_min + 
                          WBC_min + 
                          WBC_max
                        ,data=nm_icu_model_df1, family="binomial")
    summary(finalICU_glm) # AIC 1311.1
    ## 
    ## Call:
    ## glm(formula = in_hospital_death ~ Age + ICUType + Albumin_min + 
    ##     Bilirubin_max + BUN_max + GCS_max + HR_max + Lactate_max + 
    ##     Na_min + pH_min + Temp_min + Urine_min + WBC_min + WBC_max, 
    ##     family = "binomial", data = nm_icu_model_df1)
    ## 
    ## Deviance Residuals: 
    ##     Min       1Q   Median       3Q      Max  
    ## -1.9438  -0.5450  -0.3479  -0.1945   2.9904  
    ## 
    ## Coefficients:
    ##                                       Estimate Std. Error z value Pr(>|z|)    
    ## (Intercept)                          16.771564   6.180202   2.714  0.00665 ** 
    ## Age                                   0.035748   0.005082   7.034 2.01e-12 ***
    ## ICUTypeCardiac Surgery Recovery Unit -1.107288   0.292041  -3.792  0.00015 ***
    ## ICUTypeMedical ICU                    0.138003   0.215368   0.641  0.52167    
    ## ICUTypeSurgical ICU                   0.123606   0.235752   0.524  0.60007    
    ## Albumin_min                          -0.330533   0.119828  -2.758  0.00581 ** 
    ## Bilirubin_max                         0.048073   0.013358   3.599  0.00032 ***
    ## BUN_max                               0.017653   0.002894   6.101 1.06e-09 ***
    ## GCS_max                              -0.177828   0.021643  -8.217  < 2e-16 ***
    ## HR_max                                0.007771   0.003215   2.417  0.01564 *  
    ## Lactate_max                           0.062615   0.033026   1.896  0.05797 .  
    ## Na_min                               -0.038723   0.014114  -2.744  0.00608 ** 
    ## pH_min                               -1.101299   0.756621  -1.456  0.14552    
    ## Temp_min                             -0.162389   0.078329  -2.073  0.03816 *  
    ## Urine_min                            -0.006031   0.002509  -2.404  0.01622 *  
    ## WBC_min                               0.072729   0.025587   2.842  0.00448 ** 
    ## WBC_max                              -0.063857   0.021592  -2.957  0.00310 ** 
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## (Dispersion parameter for binomial family taken to be 1)
    ## 
    ##     Null deviance: 1604.2  on 1914  degrees of freedom
    ## Residual deviance: 1277.1  on 1898  degrees of freedom
    ## AIC: 1311.1
    ## 
    ## Number of Fisher Scoring iterations: 6
    ### testing interactions
    
    # finalICU_glm_AgeCr = finalICU_glm + Age:Creatinine_max
    finalICU_glm_AgeCr <- glm(in_hospital_death ~ 
                          Age +
                          ICUType + 
                          Albumin_min + 
                          Bilirubin_max +
                          BUN_max + 
                          GCS_max + 
                          HR_max + 
                          Lactate_max + 
                          Na_min + 
                          pH_min + 
                          Temp_min + 
                          Urine_min + 
                          WBC_min + 
                          WBC_max +
                          
                          # interaction term  
                          Age:Creatinine_max # creatinine generally increases with age
                        , data=nm_icu_model_df1, family="binomial")
    summary(finalICU_glm_AgeCr) # AIC 1311.6
    ## 
    ## Call:
    ## glm(formula = in_hospital_death ~ Age + ICUType + Albumin_min + 
    ##     Bilirubin_max + BUN_max + GCS_max + HR_max + Lactate_max + 
    ##     Na_min + pH_min + Temp_min + Urine_min + WBC_min + WBC_max + 
    ##     Age:Creatinine_max, family = "binomial", data = nm_icu_model_df1)
    ## 
    ## Deviance Residuals: 
    ##     Min       1Q   Median       3Q      Max  
    ## -2.0058  -0.5441  -0.3471  -0.1923   3.0126  
    ## 
    ## Coefficients:
    ##                                        Estimate Std. Error z value Pr(>|z|)    
    ## (Intercept)                          17.2042718  6.2610209   2.748 0.005999 ** 
    ## Age                                   0.0364778  0.0051215   7.123 1.06e-12 ***
    ## ICUTypeCardiac Surgery Recovery Unit -1.1050590  0.2924687  -3.778 0.000158 ***
    ## ICUTypeMedical ICU                    0.1432747  0.2157226   0.664 0.506587    
    ## ICUTypeSurgical ICU                   0.1270050  0.2361028   0.538 0.590631    
    ## Albumin_min                          -0.3200195  0.1202310  -2.662 0.007775 ** 
    ## Bilirubin_max                         0.0482335  0.0133563   3.611 0.000305 ***
    ## BUN_max                               0.0207435  0.0038808   5.345 9.04e-08 ***
    ## GCS_max                              -0.1779749  0.0216652  -8.215  < 2e-16 ***
    ## HR_max                                0.0075795  0.0032185   2.355 0.018524 *  
    ## Lactate_max                           0.0634961  0.0330932   1.919 0.055022 .  
    ## Na_min                               -0.0404502  0.0141531  -2.858 0.004263 ** 
    ## pH_min                               -1.1307197  0.7701256  -1.468 0.142042    
    ## Temp_min                             -0.1627020  0.0784203  -2.075 0.038010 *  
    ## Urine_min                            -0.0064029  0.0025826  -2.479 0.013166 *  
    ## WBC_min                               0.0713769  0.0255692   2.792 0.005246 ** 
    ## WBC_max                              -0.0630659  0.0215458  -2.927 0.003422 ** 
    ## Age:Creatinine_max                   -0.0010441  0.0008793  -1.187 0.235047    
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## (Dispersion parameter for binomial family taken to be 1)
    ## 
    ##     Null deviance: 1604.2  on 1914  degrees of freedom
    ## Residual deviance: 1275.6  on 1897  degrees of freedom
    ## AIC: 1311.6
    ## 
    ## Number of Fisher Scoring iterations: 6
    # finalICU_glm_AgeTemp = finalICU_glm + Age:Temp_min
    finalICU_glm_AgeTemp <- glm(in_hospital_death ~ 
                          Age +
                          ICUType + 
                          Albumin_min + 
                          Bilirubin_max +
                          BUN_max + 
                          GCS_max + 
                          HR_max + 
                          Lactate_max + 
                          Na_min + 
                          pH_min + 
                          Temp_min + 
                          Urine_min + 
                          WBC_min + 
                          WBC_max +
                          
                          # interaction term  
                          Age:Temp_min # low temp more often associated with illness in the elderly e.g. cold sepsis
                        , data=nm_icu_model_df1, family="binomial")
    summary(finalICU_glm_AgeTemp) # AIC 1313.1
    ## 
    ## Call:
    ## glm(formula = in_hospital_death ~ Age + ICUType + Albumin_min + 
    ##     Bilirubin_max + BUN_max + GCS_max + HR_max + Lactate_max + 
    ##     Na_min + pH_min + Temp_min + Urine_min + WBC_min + WBC_max + 
    ##     Age:Temp_min, family = "binomial", data = nm_icu_model_df1)
    ## 
    ## Deviance Residuals: 
    ##     Min       1Q   Median       3Q      Max  
    ## -1.9443  -0.5449  -0.3478  -0.1945   2.9890  
    ## 
    ## Coefficients:
    ##                                       Estimate Std. Error z value Pr(>|z|)    
    ## (Intercept)                          16.295971  11.197145   1.455 0.145567    
    ## Age                                   0.042771   0.137985   0.310 0.756586    
    ## ICUTypeCardiac Surgery Recovery Unit -1.107832   0.292268  -3.790 0.000150 ***
    ## ICUTypeMedical ICU                    0.137945   0.215393   0.640 0.521891    
    ## ICUTypeSurgical ICU                   0.123568   0.235776   0.524 0.600216    
    ## Albumin_min                          -0.330377   0.119870  -2.756 0.005849 ** 
    ## Bilirubin_max                         0.048084   0.013358   3.600 0.000319 ***
    ## BUN_max                               0.017650   0.002894   6.098 1.07e-09 ***
    ## GCS_max                              -0.177900   0.021689  -8.202 2.36e-16 ***
    ## HR_max                                0.007774   0.003216   2.418 0.015615 *  
    ## Lactate_max                           0.062704   0.033071   1.896 0.057949 .  
    ## Na_min                               -0.038711   0.014117  -2.742 0.006103 ** 
    ## pH_min                               -1.101215   0.756691  -1.455 0.145585    
    ## Temp_min                             -0.149186   0.270756  -0.551 0.581637    
    ## Urine_min                            -0.006032   0.002509  -2.404 0.016222 *  
    ## WBC_min                               0.072782   0.025611   2.842 0.004486 ** 
    ## WBC_max                              -0.063901   0.021611  -2.957 0.003108 ** 
    ## Age:Temp_min                         -0.000196   0.003848  -0.051 0.959380    
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## (Dispersion parameter for binomial family taken to be 1)
    ## 
    ##     Null deviance: 1604.2  on 1914  degrees of freedom
    ## Residual deviance: 1277.1  on 1897  degrees of freedom
    ## AIC: 1313.1
    ## 
    ## Number of Fisher Scoring iterations: 6
    # finalICU_glm_AgeWeight = finalICU_glm + Age:Weight_max (rather than using Weight_min previously)
    finalICU_glm_AgeWeight <- glm(in_hospital_death ~ 
                          Age +
                          ICUType + 
                          Albumin_min + 
                          Bilirubin_max +
                          BUN_max + 
                          GCS_max + 
                          HR_max + 
                          Lactate_max + 
                          Na_min + 
                          pH_min + 
                          Temp_min + 
                          Urine_min + 
                          WBC_min + 
                          WBC_max +
                          
                          # interaction term  
                          Age:Weight_max # weight generally decreases with age
                        , data=nm_icu_model_df1, family="binomial")
    summary(finalICU_glm_AgeWeight) # AIC 1311
    ## 
    ## Call:
    ## glm(formula = in_hospital_death ~ Age + ICUType + Albumin_min + 
    ##     Bilirubin_max + BUN_max + GCS_max + HR_max + Lactate_max + 
    ##     Na_min + pH_min + Temp_min + Urine_min + WBC_min + WBC_max + 
    ##     Age:Weight_max, family = "binomial", data = nm_icu_model_df1)
    ## 
    ## Deviance Residuals: 
    ##     Min       1Q   Median       3Q      Max  
    ## -2.0043  -0.5467  -0.3475  -0.1917   3.0545  
    ## 
    ## Coefficients:
    ##                                        Estimate Std. Error z value Pr(>|z|)    
    ## (Intercept)                           1.710e+01  6.323e+00   2.704 0.006847 ** 
    ## Age                                   3.949e-02  5.739e-03   6.882 5.92e-12 ***
    ## ICUTypeCardiac Surgery Recovery Unit -1.068e+00  2.934e-01  -3.639 0.000273 ***
    ## ICUTypeMedical ICU                    1.308e-01  2.157e-01   0.607 0.544177    
    ## ICUTypeSurgical ICU                   1.330e-01  2.361e-01   0.563 0.573176    
    ## Albumin_min                          -3.363e-01  1.199e-01  -2.805 0.005039 ** 
    ## Bilirubin_max                         4.833e-02  1.338e-02   3.612 0.000304 ***
    ## BUN_max                               1.823e-02  2.924e-03   6.233 4.57e-10 ***
    ## GCS_max                              -1.790e-01  2.169e-02  -8.253  < 2e-16 ***
    ## HR_max                                7.452e-03  3.230e-03   2.307 0.021042 *  
    ## Lactate_max                           6.444e-02  3.315e-02   1.944 0.051930 .  
    ## Na_min                               -3.907e-02  1.409e-02  -2.772 0.005564 ** 
    ## pH_min                               -1.201e+00  7.874e-01  -1.525 0.127242    
    ## Temp_min                             -1.458e-01  7.896e-02  -1.846 0.064889 .  
    ## Urine_min                            -5.978e-03  2.507e-03  -2.384 0.017109 *  
    ## WBC_min                               7.239e-02  2.559e-02   2.829 0.004674 ** 
    ## WBC_max                              -6.299e-02  2.162e-02  -2.914 0.003568 ** 
    ## Age:Weight_max                       -7.005e-05  5.052e-05  -1.387 0.165553    
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## (Dispersion parameter for binomial family taken to be 1)
    ## 
    ##     Null deviance: 1604.2  on 1914  degrees of freedom
    ## Residual deviance: 1275.1  on 1897  degrees of freedom
    ## AIC: 1311.1
    ## 
    ## Number of Fisher Scoring iterations: 6
    # finalICU_glm_AgeAlbumin = finalICU_glm + Age:Albumin_min
    finalICU_glm_AgeAlbumin <- glm(in_hospital_death ~ 
                          Age +
                          ICUType + 
                          Albumin_min + 
                          Bilirubin_max +
                          BUN_max + 
                          GCS_max + 
                          HR_max + 
                          Lactate_max + 
                          Na_min + 
                          pH_min + 
                          Temp_min + 
                          Urine_min + 
                          WBC_min + 
                          WBC_max +
                          
                          # interaction term  
                          Age:Albumin_min # albumin generally decreases with age
                        , data=nm_icu_model_df1, family="binomial")
    summary(finalICU_glm_AgeAlbumin) # AIC 1309
    ## 
    ## Call:
    ## glm(formula = in_hospital_death ~ Age + ICUType + Albumin_min + 
    ##     Bilirubin_max + BUN_max + GCS_max + HR_max + Lactate_max + 
    ##     Na_min + pH_min + Temp_min + Urine_min + WBC_min + WBC_max + 
    ##     Age:Albumin_min, family = "binomial", data = nm_icu_model_df1)
    ## 
    ## Deviance Residuals: 
    ##     Min       1Q   Median       3Q      Max  
    ## -1.9359  -0.5523  -0.3464  -0.1840   3.0218  
    ## 
    ## Coefficients:
    ##                                       Estimate Std. Error z value Pr(>|z|)    
    ## (Intercept)                          19.347306   6.173815   3.134 0.001726 ** 
    ## Age                                  -0.004992   0.021570  -0.231 0.816990    
    ## ICUTypeCardiac Surgery Recovery Unit -1.101538   0.292134  -3.771 0.000163 ***
    ## ICUTypeMedical ICU                    0.125775   0.215780   0.583 0.559971    
    ## ICUTypeSurgical ICU                   0.125709   0.235844   0.533 0.594021    
    ## Albumin_min                          -1.355174   0.548435  -2.471 0.013474 *  
    ## Bilirubin_max                         0.048750   0.013410   3.635 0.000278 ***
    ## BUN_max                               0.017767   0.002897   6.133 8.62e-10 ***
    ## GCS_max                              -0.177107   0.021686  -8.167 3.16e-16 ***
    ## HR_max                                0.007565   0.003220   2.350 0.018782 *  
    ## Lactate_max                           0.062344   0.033194   1.878 0.060356 .  
    ## Na_min                               -0.037919   0.014226  -2.666 0.007687 ** 
    ## pH_min                               -1.070276   0.727151  -1.472 0.141054    
    ## Temp_min                             -0.164386   0.078641  -2.090 0.036588 *  
    ## Urine_min                            -0.005912   0.002509  -2.356 0.018449 *  
    ## WBC_min                               0.074097   0.025585   2.896 0.003778 ** 
    ## WBC_max                              -0.063696   0.021561  -2.954 0.003135 ** 
    ## Age:Albumin_min                       0.014583   0.007592   1.921 0.054741 .  
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## (Dispersion parameter for binomial family taken to be 1)
    ## 
    ##     Null deviance: 1604.2  on 1914  degrees of freedom
    ## Residual deviance: 1273.4  on 1897  degrees of freedom
    ## AIC: 1309.4
    ## 
    ## Number of Fisher Scoring iterations: 6
    # finalICU_glm_AgeICUType = finalICU_glm + Age:ICUType
    finalICU_glm_AgeICUType <- glm(in_hospital_death ~ 
                          Age +
                          ICUType + 
                          Albumin_min + 
                          Bilirubin_max +
                          BUN_max + 
                          GCS_max + 
                          HR_max + 
                          Lactate_max + 
                          Na_min + 
                          pH_min + 
                          Temp_min + 
                          Urine_min + 
                          WBC_min + 
                          WBC_max +
                          
                          # interaction term  
                          Age:ICUType # age is likely to be related to ICU type 
                                      # e.g. elderly more likely to have poor outcome 
                                      # after surgery requiring post-op ICU support
                        , data=nm_icu_model_df1, family="binomial")
    summary(finalICU_glm_AgeICUType) # AIC 1307
    ## 
    ## Call:
    ## glm(formula = in_hospital_death ~ Age + ICUType + Albumin_min + 
    ##     Bilirubin_max + BUN_max + GCS_max + HR_max + Lactate_max + 
    ##     Na_min + pH_min + Temp_min + Urine_min + WBC_min + WBC_max + 
    ##     Age:ICUType, family = "binomial", data = nm_icu_model_df1)
    ## 
    ## Deviance Residuals: 
    ##     Min       1Q   Median       3Q      Max  
    ## -1.9579  -0.5488  -0.3415  -0.1920   3.1057  
    ## 
    ## Coefficients:
    ##                                           Estimate Std. Error z value Pr(>|z|)
    ## (Intercept)                              17.858479   6.317804   2.827 0.004703
    ## Age                                       0.028563   0.015297   1.867 0.061863
    ## ICUTypeCardiac Surgery Recovery Unit     -0.137499   1.721588  -0.080 0.936343
    ## ICUTypeMedical ICU                        0.199901   1.243496   0.161 0.872284
    ## ICUTypeSurgical ICU                      -2.152542   1.365680  -1.576 0.114987
    ## Albumin_min                              -0.327271   0.121006  -2.705 0.006839
    ## Bilirubin_max                             0.047961   0.013482   3.557 0.000374
    ## BUN_max                                   0.018057   0.002897   6.232  4.6e-10
    ## GCS_max                                  -0.179741   0.021736  -8.269  < 2e-16
    ## HR_max                                    0.008283   0.003228   2.566 0.010299
    ## Lactate_max                               0.061953   0.033160   1.868 0.061719
    ## Na_min                                   -0.039643   0.014137  -2.804 0.005043
    ## pH_min                                   -1.121623   0.768555  -1.459 0.144457
    ## Temp_min                                 -0.170873   0.079380  -2.153 0.031350
    ## Urine_min                                -0.006144   0.002517  -2.441 0.014655
    ## WBC_min                                   0.072986   0.025797   2.829 0.004666
    ## WBC_max                                  -0.065673   0.021802  -3.012 0.002594
    ## Age:ICUTypeCardiac Surgery Recovery Unit -0.013777   0.023475  -0.587 0.557276
    ## Age:ICUTypeMedical ICU                   -0.001538   0.016578  -0.093 0.926097
    ## Age:ICUTypeSurgical ICU                   0.031959   0.018202   1.756 0.079123
    ##                                             
    ## (Intercept)                              ** 
    ## Age                                      .  
    ## ICUTypeCardiac Surgery Recovery Unit        
    ## ICUTypeMedical ICU                          
    ## ICUTypeSurgical ICU                         
    ## Albumin_min                              ** 
    ## Bilirubin_max                            ***
    ## BUN_max                                  ***
    ## GCS_max                                  ***
    ## HR_max                                   *  
    ## Lactate_max                              .  
    ## Na_min                                   ** 
    ## pH_min                                      
    ## Temp_min                                 *  
    ## Urine_min                                *  
    ## WBC_min                                  ** 
    ## WBC_max                                  ** 
    ## Age:ICUTypeCardiac Surgery Recovery Unit    
    ## Age:ICUTypeMedical ICU                      
    ## Age:ICUTypeSurgical ICU                  .  
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## (Dispersion parameter for binomial family taken to be 1)
    ## 
    ##     Null deviance: 1604.2  on 1914  degrees of freedom
    ## Residual deviance: 1266.9  on 1895  degrees of freedom
    ## AIC: 1306.9
    ## 
    ## Number of Fisher Scoring iterations: 6
    # Code from previous attempt at task 1
    # Gender:HCT, PaO2:RespRate not tested because they are not in the final model
    
    # Anova testing for the new models
    lapply(list(finalICU_glm_AgeCr, finalICU_glm_AgeTemp, finalICU_glm_AgeWeight,
                finalICU_glm_AgeAlbumin, finalICU_glm_AgeICUType), 
           function(x) {print(anova(finalICU_glm, x, test="Chisq"))} )
    ## Analysis of Deviance Table
    ## 
    ## Model 1: in_hospital_death ~ Age + ICUType + Albumin_min + Bilirubin_max + 
    ##     BUN_max + GCS_max + HR_max + Lactate_max + Na_min + pH_min + 
    ##     Temp_min + Urine_min + WBC_min + WBC_max
    ## Model 2: in_hospital_death ~ Age + ICUType + Albumin_min + Bilirubin_max + 
    ##     BUN_max + GCS_max + HR_max + Lactate_max + Na_min + pH_min + 
    ##     Temp_min + Urine_min + WBC_min + WBC_max + Age:Creatinine_max
    ##   Resid. Df Resid. Dev Df Deviance Pr(>Chi)
    ## 1      1898     1277.1                     
    ## 2      1897     1275.6  1   1.4776   0.2242
    ## Analysis of Deviance Table
    ## 
    ## Model 1: in_hospital_death ~ Age + ICUType + Albumin_min + Bilirubin_max + 
    ##     BUN_max + GCS_max + HR_max + Lactate_max + Na_min + pH_min + 
    ##     Temp_min + Urine_min + WBC_min + WBC_max
    ## Model 2: in_hospital_death ~ Age + ICUType + Albumin_min + Bilirubin_max + 
    ##     BUN_max + GCS_max + HR_max + Lactate_max + Na_min + pH_min + 
    ##     Temp_min + Urine_min + WBC_min + WBC_max + Age:Temp_min
    ##   Resid. Df Resid. Dev Df  Deviance Pr(>Chi)
    ## 1      1898     1277.1                      
    ## 2      1897     1277.1  1 0.0025966   0.9594
    ## Analysis of Deviance Table
    ## 
    ## Model 1: in_hospital_death ~ Age + ICUType + Albumin_min + Bilirubin_max + 
    ##     BUN_max + GCS_max + HR_max + Lactate_max + Na_min + pH_min + 
    ##     Temp_min + Urine_min + WBC_min + WBC_max
    ## Model 2: in_hospital_death ~ Age + ICUType + Albumin_min + Bilirubin_max + 
    ##     BUN_max + GCS_max + HR_max + Lactate_max + Na_min + pH_min + 
    ##     Temp_min + Urine_min + WBC_min + WBC_max + Age:Weight_max
    ##   Resid. Df Resid. Dev Df Deviance Pr(>Chi)
    ## 1      1898     1277.1                     
    ## 2      1897     1275.1  1   1.9802   0.1594
    ## Analysis of Deviance Table
    ## 
    ## Model 1: in_hospital_death ~ Age + ICUType + Albumin_min + Bilirubin_max + 
    ##     BUN_max + GCS_max + HR_max + Lactate_max + Na_min + pH_min + 
    ##     Temp_min + Urine_min + WBC_min + WBC_max
    ## Model 2: in_hospital_death ~ Age + ICUType + Albumin_min + Bilirubin_max + 
    ##     BUN_max + GCS_max + HR_max + Lactate_max + Na_min + pH_min + 
    ##     Temp_min + Urine_min + WBC_min + WBC_max + Age:Albumin_min
    ##   Resid. Df Resid. Dev Df Deviance Pr(>Chi)  
    ## 1      1898     1277.1                       
    ## 2      1897     1273.4  1   3.6995  0.05443 .
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## Analysis of Deviance Table
    ## 
    ## Model 1: in_hospital_death ~ Age + ICUType + Albumin_min + Bilirubin_max + 
    ##     BUN_max + GCS_max + HR_max + Lactate_max + Na_min + pH_min + 
    ##     Temp_min + Urine_min + WBC_min + WBC_max
    ## Model 2: in_hospital_death ~ Age + ICUType + Albumin_min + Bilirubin_max + 
    ##     BUN_max + GCS_max + HR_max + Lactate_max + Na_min + pH_min + 
    ##     Temp_min + Urine_min + WBC_min + WBC_max + Age:ICUType
    ##   Resid. Df Resid. Dev Df Deviance Pr(>Chi)  
    ## 1      1898     1277.1                       
    ## 2      1895     1266.9  3   10.254  0.01653 *
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## [[1]]
    ## Analysis of Deviance Table
    ## 
    ## Model 1: in_hospital_death ~ Age + ICUType + Albumin_min + Bilirubin_max + 
    ##     BUN_max + GCS_max + HR_max + Lactate_max + Na_min + pH_min + 
    ##     Temp_min + Urine_min + WBC_min + WBC_max
    ## Model 2: in_hospital_death ~ Age + ICUType + Albumin_min + Bilirubin_max + 
    ##     BUN_max + GCS_max + HR_max + Lactate_max + Na_min + pH_min + 
    ##     Temp_min + Urine_min + WBC_min + WBC_max + Age:Creatinine_max
    ##   Resid. Df Resid. Dev Df Deviance Pr(>Chi)
    ## 1      1898     1277.1                     
    ## 2      1897     1275.6  1   1.4776   0.2242
    ## 
    ## [[2]]
    ## Analysis of Deviance Table
    ## 
    ## Model 1: in_hospital_death ~ Age + ICUType + Albumin_min + Bilirubin_max + 
    ##     BUN_max + GCS_max + HR_max + Lactate_max + Na_min + pH_min + 
    ##     Temp_min + Urine_min + WBC_min + WBC_max
    ## Model 2: in_hospital_death ~ Age + ICUType + Albumin_min + Bilirubin_max + 
    ##     BUN_max + GCS_max + HR_max + Lactate_max + Na_min + pH_min + 
    ##     Temp_min + Urine_min + WBC_min + WBC_max + Age:Temp_min
    ##   Resid. Df Resid. Dev Df  Deviance Pr(>Chi)
    ## 1      1898     1277.1                      
    ## 2      1897     1277.1  1 0.0025966   0.9594
    ## 
    ## [[3]]
    ## Analysis of Deviance Table
    ## 
    ## Model 1: in_hospital_death ~ Age + ICUType + Albumin_min + Bilirubin_max + 
    ##     BUN_max + GCS_max + HR_max + Lactate_max + Na_min + pH_min + 
    ##     Temp_min + Urine_min + WBC_min + WBC_max
    ## Model 2: in_hospital_death ~ Age + ICUType + Albumin_min + Bilirubin_max + 
    ##     BUN_max + GCS_max + HR_max + Lactate_max + Na_min + pH_min + 
    ##     Temp_min + Urine_min + WBC_min + WBC_max + Age:Weight_max
    ##   Resid. Df Resid. Dev Df Deviance Pr(>Chi)
    ## 1      1898     1277.1                     
    ## 2      1897     1275.1  1   1.9802   0.1594
    ## 
    ## [[4]]
    ## Analysis of Deviance Table
    ## 
    ## Model 1: in_hospital_death ~ Age + ICUType + Albumin_min + Bilirubin_max + 
    ##     BUN_max + GCS_max + HR_max + Lactate_max + Na_min + pH_min + 
    ##     Temp_min + Urine_min + WBC_min + WBC_max
    ## Model 2: in_hospital_death ~ Age + ICUType + Albumin_min + Bilirubin_max + 
    ##     BUN_max + GCS_max + HR_max + Lactate_max + Na_min + pH_min + 
    ##     Temp_min + Urine_min + WBC_min + WBC_max + Age:Albumin_min
    ##   Resid. Df Resid. Dev Df Deviance Pr(>Chi)  
    ## 1      1898     1277.1                       
    ## 2      1897     1273.4  1   3.6995  0.05443 .
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## [[5]]
    ## Analysis of Deviance Table
    ## 
    ## Model 1: in_hospital_death ~ Age + ICUType + Albumin_min + Bilirubin_max + 
    ##     BUN_max + GCS_max + HR_max + Lactate_max + Na_min + pH_min + 
    ##     Temp_min + Urine_min + WBC_min + WBC_max
    ## Model 2: in_hospital_death ~ Age + ICUType + Albumin_min + Bilirubin_max + 
    ##     BUN_max + GCS_max + HR_max + Lactate_max + Na_min + pH_min + 
    ##     Temp_min + Urine_min + WBC_min + WBC_max + Age:ICUType
    ##   Resid. Df Resid. Dev Df Deviance Pr(>Chi)  
    ## 1      1898     1277.1                       
    ## 2      1895     1266.9  3   10.254  0.01653 *
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## Result: borderline effect for age:albumin (p=0.054)
    ##         significant effect for age:icutype (p=0.016)
    
    
    # Input the significant interactions into the model
    finalICU_glm_interactions <- glm(in_hospital_death ~ 
                          Age +
                          ICUType + 
                          Albumin_min + 
                          Bilirubin_max +
                          BUN_max + 
                          GCS_max + 
                          HR_max + 
                          Lactate_max + 
                          Na_min + 
                          pH_min + 
                          Temp_min + 
                          Urine_min + 
                          WBC_min + 
                          WBC_max +
                          
                          # significant interaction terms
                          Age:ICUType + Age:Albumin_min
                        , data=nm_icu_model_df1, family="binomial")
    summary(finalICU_glm_interactions) # AIC 1305 (lowest so far - lower than just including age:icutype)
    ## 
    ## Call:
    ## glm(formula = in_hospital_death ~ Age + ICUType + Albumin_min + 
    ##     Bilirubin_max + BUN_max + GCS_max + HR_max + Lactate_max + 
    ##     Na_min + pH_min + Temp_min + Urine_min + WBC_min + WBC_max + 
    ##     Age:ICUType + Age:Albumin_min, family = "binomial", data = nm_icu_model_df1)
    ## 
    ## Deviance Residuals: 
    ##     Min       1Q   Median       3Q      Max  
    ## -1.9494  -0.5533  -0.3360  -0.1854   3.2388  
    ## 
    ## Coefficients:
    ##                                           Estimate Std. Error z value Pr(>|z|)
    ## (Intercept)                              20.855206   6.365565   3.276  0.00105
    ## Age                                      -0.018285   0.028752  -0.636  0.52480
    ## ICUTypeCardiac Surgery Recovery Unit     -0.562192   1.733448  -0.324  0.74570
    ## ICUTypeMedical ICU                       -0.243286   1.265623  -0.192  0.84756
    ## ICUTypeSurgical ICU                      -2.505360   1.374546  -1.823  0.06835
    ## Albumin_min                              -1.384342   0.567281  -2.440  0.01467
    ## Bilirubin_max                             0.048779   0.013523   3.607  0.00031
    ## BUN_max                                   0.018215   0.002902   6.276 3.47e-10
    ## GCS_max                                  -0.178502   0.021748  -8.208 2.26e-16
    ## HR_max                                    0.008056   0.003232   2.492  0.01269
    ## Lactate_max                               0.062277   0.033295   1.870  0.06142
    ## Na_min                                   -0.038919   0.014253  -2.731  0.00632
    ## pH_min                                   -1.084124   0.737653  -1.470  0.14164
    ## Temp_min                                 -0.172788   0.079499  -2.173  0.02974
    ## Urine_min                                -0.006015   0.002511  -2.395  0.01660
    ## WBC_min                                   0.074082   0.025771   2.875  0.00405
    ## WBC_max                                  -0.065411   0.021751  -3.007  0.00264
    ## Age:ICUTypeCardiac Surgery Recovery Unit -0.008024   0.023597  -0.340  0.73383
    ## Age:ICUTypeMedical ICU                    0.004228   0.016843   0.251  0.80181
    ## Age:ICUTypeSurgical ICU                   0.036583   0.018295   2.000  0.04554
    ## Age:Albumin_min                           0.014994   0.007834   1.914  0.05563
    ##                                             
    ## (Intercept)                              ** 
    ## Age                                         
    ## ICUTypeCardiac Surgery Recovery Unit        
    ## ICUTypeMedical ICU                          
    ## ICUTypeSurgical ICU                      .  
    ## Albumin_min                              *  
    ## Bilirubin_max                            ***
    ## BUN_max                                  ***
    ## GCS_max                                  ***
    ## HR_max                                   *  
    ## Lactate_max                              .  
    ## Na_min                                   ** 
    ## pH_min                                      
    ## Temp_min                                 *  
    ## Urine_min                                *  
    ## WBC_min                                  ** 
    ## WBC_max                                  ** 
    ## Age:ICUTypeCardiac Surgery Recovery Unit    
    ## Age:ICUTypeMedical ICU                      
    ## Age:ICUTypeSurgical ICU                  *  
    ## Age:Albumin_min                          .  
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## (Dispersion parameter for binomial family taken to be 1)
    ## 
    ##     Null deviance: 1604.2  on 1914  degrees of freedom
    ## Residual deviance: 1263.2  on 1894  degrees of freedom
    ## AIC: 1305.2
    ## 
    ## Number of Fisher Scoring iterations: 6

    ? Do we include this poisson section, or just discuss it? ***

    Testing the modified poisson regression, as the outcome is 14% in this data (>10% - common)

    #################################################################################
    # NEED TO DECIDE WHETHER TO INCLUDE THIS SECTION
    
    # test using modified poisson regression for more common outcomes on the same covariates as above
    
    finalICU_glm_poisson <- glm(in_hospital_death ~ 
                          Age +
                          ICUType + 
                          Albumin_min + 
                          Bilirubin_max +
                          BUN_max + 
                          GCS_max + 
                          HR_max + 
                          Lactate_max + 
                          Na_min + 
                          pH_min + 
                          Temp_min + 
                          Urine_min + 
                          WBC_min + 
                          WBC_max
                          
                          # changed dataset to fit what we use for rest of task 1
                        , data=nm_icu_model_df1, family="poisson"(link="log")) 
    
    summary(finalICU_glm_poisson) # AIC 1432.5
    ## 
    ## Call:
    ## glm(formula = in_hospital_death ~ Age + ICUType + Albumin_min + 
    ##     Bilirubin_max + BUN_max + GCS_max + HR_max + Lactate_max + 
    ##     Na_min + pH_min + Temp_min + Urine_min + WBC_min + WBC_max, 
    ##     family = poisson(link = "log"), data = nm_icu_model_df1)
    ## 
    ## Deviance Residuals: 
    ##     Min       1Q   Median       3Q      Max  
    ## -1.6209  -0.5193  -0.3710  -0.2358   2.4255  
    ## 
    ## Coefficients:
    ##                                       Estimate Std. Error z value Pr(>|z|)    
    ## (Intercept)                           8.073192   3.021690   2.672 0.007546 ** 
    ## Age                                   0.027348   0.004236   6.456 1.07e-10 ***
    ## ICUTypeCardiac Surgery Recovery Unit -0.931815   0.257304  -3.621 0.000293 ***
    ## ICUTypeMedical ICU                    0.071266   0.178517   0.399 0.689738    
    ## ICUTypeSurgical ICU                   0.069801   0.196761   0.355 0.722775    
    ## Albumin_min                          -0.254955   0.097939  -2.603 0.009236 ** 
    ## Bilirubin_max                         0.030818   0.008837   3.487 0.000488 ***
    ## BUN_max                               0.010432   0.001960   5.324 1.02e-07 ***
    ## GCS_max                              -0.121144   0.016972  -7.138 9.47e-13 ***
    ## HR_max                                0.005007   0.002452   2.042 0.041161 *  
    ## Lactate_max                           0.026759   0.020284   1.319 0.187094    
    ## Na_min                               -0.029362   0.011261  -2.607 0.009122 ** 
    ## pH_min                               -0.367651   0.221104  -1.663 0.096353 .  
    ## Temp_min                             -0.103899   0.050598  -2.053 0.040031 *  
    ## Urine_min                            -0.004947   0.002199  -2.249 0.024500 *  
    ## WBC_min                               0.045769   0.020587   2.223 0.026203 *  
    ## WBC_max                              -0.039644   0.017408  -2.277 0.022765 *  
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## (Dispersion parameter for poisson family taken to be 1)
    ## 
    ##     Null deviance: 1082.2  on 1914  degrees of freedom
    ## Residual deviance:  832.5  on 1898  degrees of freedom
    ## AIC: 1432.5
    ## 
    ## Number of Fisher Scoring iterations: 6
    # fewer significant variables (likely as CI can be wider in poisson)
    # but the variables that are significant were also significant in the logistic model
    
    # examine ORs from logistic regression
    options(scipen=999) # turn off scientific notation
    exp(coef(finalICU_glm_interactions))
    ##                              (Intercept) 
    ##                      1141039705.79856825 
    ##                                      Age 
    ##                               0.98188117 
    ##     ICUTypeCardiac Surgery Recovery Unit 
    ##                               0.56995835 
    ##                       ICUTypeMedical ICU 
    ##                               0.78404694 
    ##                      ICUTypeSurgical ICU 
    ##                               0.08164616 
    ##                              Albumin_min 
    ##                               0.25048853 
    ##                            Bilirubin_max 
    ##                               1.04998791 
    ##                                  BUN_max 
    ##                               1.01838146 
    ##                                  GCS_max 
    ##                               0.83652254 
    ##                                   HR_max 
    ##                               1.00808840 
    ##                              Lactate_max 
    ##                               1.06425731 
    ##                                   Na_min 
    ##                               0.96182843 
    ##                                   pH_min 
    ##                               0.33819783 
    ##                                 Temp_min 
    ##                               0.84131613 
    ##                                Urine_min 
    ##                               0.99400267 
    ##                                  WBC_min 
    ##                               1.07689505 
    ##                                  WBC_max 
    ##                               0.93668260 
    ## Age:ICUTypeCardiac Surgery Recovery Unit 
    ##                               0.99200823 
    ##                   Age:ICUTypeMedical ICU 
    ##                               1.00423652 
    ##                  Age:ICUTypeSurgical ICU 
    ##                               1.03725988 
    ##                          Age:Albumin_min 
    ##                               1.01510738
    # examine RRs from logistic regression
    exp(coef(finalICU_glm_poisson))
    ##                          (Intercept)                                  Age 
    ##                         3207.3233507                            1.0277252 
    ## ICUTypeCardiac Surgery Recovery Unit                   ICUTypeMedical ICU 
    ##                            0.3938384                            1.0738665 
    ##                  ICUTypeSurgical ICU                          Albumin_min 
    ##                            1.0722952                            0.7749514 
    ##                        Bilirubin_max                              BUN_max 
    ##                            1.0312976                            1.0104869 
    ##                              GCS_max                               HR_max 
    ##                            0.8859060                            1.0050193 
    ##                          Lactate_max                               Na_min 
    ##                            1.0271202                            0.9710651 
    ##                               pH_min                             Temp_min 
    ##                            0.6923591                            0.9013161 
    ##                            Urine_min                              WBC_min 
    ##                            0.9950657                            1.0468326 
    ##                              WBC_max 
    ##                            0.9611318
    # the ORs and RRs appear very similar --> check the actual differences
    exp(coef(finalICU_glm_interactions))-exp(coef(finalICU_glm_poisson))
    ## Warning in exp(coef(finalICU_glm_interactions)) -
    ## exp(coef(finalICU_glm_poisson)): longer object length is not a multiple of
    ## shorter object length
    ##                              (Intercept) 
    ##                     1141036498.475217581 
    ##                                      Age 
    ##                             -0.045844015 
    ##     ICUTypeCardiac Surgery Recovery Unit 
    ##                              0.176119966 
    ##                       ICUTypeMedical ICU 
    ##                             -0.289819588 
    ##                      ICUTypeSurgical ICU 
    ##                             -0.990649004 
    ##                              Albumin_min 
    ##                             -0.524462846 
    ##                            Bilirubin_max 
    ##                              0.018690293 
    ##                                  BUN_max 
    ##                              0.007894516 
    ##                                  GCS_max 
    ##                             -0.049383432 
    ##                                   HR_max 
    ##                              0.003069046 
    ##                              Lactate_max 
    ##                              0.037137079 
    ##                                   Na_min 
    ##                             -0.009236685 
    ##                                   pH_min 
    ##                             -0.354161276 
    ##                                 Temp_min 
    ##                             -0.059999922 
    ##                                Urine_min 
    ##                             -0.001063029 
    ##                                  WBC_min 
    ##                              0.030062482 
    ##                                  WBC_max 
    ##                             -0.024449219 
    ## Age:ICUTypeCardiac Surgery Recovery Unit 
    ##                          -3206.331342461 
    ##                   Age:ICUTypeMedical ICU 
    ##                             -0.023488663 
    ##                  Age:ICUTypeSurgical ICU 
    ##                              0.643421501 
    ##                          Age:Albumin_min 
    ##                             -0.058759150
    # the intercept is very different (by 1141036498?!) - not sure how to interpret that. the other estimates are very similar
    
    # perhaps the logistic model is therefore justified? just need to be careful in interpretation using 'odds' rather than 'risk'
    
    #################################################################################

    Final model diagnostics:

    ### Goodness of fit using bins df1 ###
    
    # add predicted probabilities to the data frame
    nm_icu_model_df1 %>% mutate(predprob=predict(finalICU_glm_interactions, type="response"),
                       linpred=predict(finalICU_glm_interactions)) %>%
    # group the data into bins based on the linear predictor fitted values
    group_by(cut(linpred, breaks=unique(quantile(linpred, (1:50)/51)))) %>%
    # summarise by bin
    summarise(death_bin=sum(in_hospital_death), predprob_bin=mean(predprob), n_bin=n()) %>%
    # add the standard error of the mean predicted probaility for each bin
    mutate(se_predprob_bin=sqrt(predprob_bin*(1 - predprob_bin)/n_bin)) %>%
    # plot it with 95% confidence interval bars
    ggplot(aes(x=predprob_bin, 
               y=death_bin/n_bin, 
               ymin=death_bin/n_bin - 1.96*se_predprob_bin,
               ymax=death_bin/n_bin + 1.96*se_predprob_bin)) +
      geom_point() + geom_linerange(colour="orange", alpha=0.4) +
      geom_abline(intercept=0, slope=1) + 
      labs(x="Predicted probability (binned)",
           y="Observed proportion (in each bin)")

    # the ideal calibration line fits within most of the dots and their 95% CI
    
    ### Goodness of fit using Hosmer Lemeshow stat ###
    
    nm_icu_model_df1 %>% mutate(predprob=predict(finalICU_glm_interactions, type="response"),
                       linpred=predict(finalICU_glm_interactions)) %>%
    group_by(cut(linpred, breaks=unique(quantile(linpred, (1:50)/51)))) %>%
    summarise(death_bin=sum(in_hospital_death), predprob_bin=mean(predprob), n_bin=n()) %>%
    mutate(se_predprob_bin=sqrt(predprob_bin*(1 - predprob_bin)/n_bin)) -> hl_df
    
    hl_stat <- with(hl_df, sum( (death_bin - n_bin*predprob_bin)^2 /
                                (n_bin* predprob_bin*(1 - predprob_bin))))
    hl <- c(hosmer_lemeshow_stat=hl_stat, hl_degrees_freedom=nrow(hl_df) - 1)
    hl
    ## hosmer_lemeshow_stat   hl_degrees_freedom 
    ##             51.77871             49.00000
    # calculate p-value
    c(p_val=1 - pchisq(hl[1], hl[2])) # the p value here is not statistically significant, indicating no lack of fit
    ## p_val.hosmer_lemeshow_stat 
    ##                  0.3659299
    ### Brier score ###
    
    get_brier <- function(model){
      predprob <- predict(model, type="response")
      Brier_score <- mean((predprob - nm_icu_model_df1$in_hospital_death)^2)
      return(Brier_score)
    }
    
    get_brier(finalICU_glm)
    ## [1] 0.1022154
    get_brier(finalICU_glm_interactions)
    ## [1] 0.1012639
    # the final model with interactions has slightly lower brier score -> lower score is better fit

    Re-fitting the model to the original data:

    #### re-fit your final model to the unimputed data frame 
    # (`icu_patients_df0.rds`) and comment on any differences you find 
    # compared to the same model fitted to the data without imputation, 
    
    df0_finalICU_glm_interactions <- glm(in_hospital_death ~ 
                          Age +
                          ICUType + 
                          Albumin_min + 
                          Bilirubin_max +
                          BUN_max + 
                          GCS_max + 
                          HR_max + 
                          Lactate_max + 
                          Na_min + 
                          pH_min + 
                          Temp_min + 
                          Urine_min + 
                          WBC_min + 
                          WBC_max +
                          
                          # significant interaction terms
                          Age:ICUType + Age:Albumin_min
                        , data=icu_patients_df0, family="binomial")
    summary(df0_finalICU_glm_interactions) 
    ## 
    ## Call:
    ## glm(formula = in_hospital_death ~ Age + ICUType + Albumin_min + 
    ##     Bilirubin_max + BUN_max + GCS_max + HR_max + Lactate_max + 
    ##     Na_min + pH_min + Temp_min + Urine_min + WBC_min + WBC_max + 
    ##     Age:ICUType + Age:Albumin_min, family = "binomial", data = icu_patients_df0)
    ## 
    ## Deviance Residuals: 
    ##     Min       1Q   Median       3Q      Max  
    ## -2.0796  -0.5851  -0.3221  -0.1132   3.0310  
    ## 
    ## Coefficients:
    ##                                           Estimate Std. Error z value Pr(>|z|)
    ## (Intercept)                              27.261971  15.618682   1.745 0.080903
    ## Age                                       0.084514   0.074238   1.138 0.254949
    ## ICUTypeCardiac Surgery Recovery Unit      0.730898   5.521035   0.132 0.894680
    ## ICUTypeMedical ICU                       -0.147974   3.093787  -0.048 0.961852
    ## ICUTypeSurgical ICU                       0.681712   3.226486   0.211 0.832664
    ## Albumin_min                              -0.111573   1.334217  -0.084 0.933355
    ## Bilirubin_max                             0.045677   0.031016   1.473 0.140834
    ## BUN_max                                   0.022170   0.006091   3.640 0.000273
    ## GCS_max                                  -0.149812   0.050123  -2.989 0.002800
    ## HR_max                                    0.014980   0.008350   1.794 0.072819
    ## Lactate_max                               0.050180   0.068215   0.736 0.461960
    ## Na_min                                   -0.065969   0.039336  -1.677 0.093532
    ## pH_min                                   -1.749588   1.905015  -0.918 0.358403
    ## Temp_min                                 -0.279081   0.158228  -1.764 0.077767
    ## Urine_min                                -0.002243   0.005209  -0.431 0.666708
    ## WBC_min                                   0.108851   0.053332   2.041 0.041250
    ## WBC_max                                  -0.107694   0.042883  -2.511 0.012027
    ## Age:ICUTypeCardiac Surgery Recovery Unit -0.054997   0.083252  -0.661 0.508866
    ## Age:ICUTypeMedical ICU                   -0.002158   0.044497  -0.049 0.961315
    ## Age:ICUTypeSurgical ICU                  -0.022395   0.046757  -0.479 0.631968
    ## Age:Albumin_min                          -0.012685   0.019718  -0.643 0.520011
    ##                                             
    ## (Intercept)                              .  
    ## Age                                         
    ## ICUTypeCardiac Surgery Recovery Unit        
    ## ICUTypeMedical ICU                          
    ## ICUTypeSurgical ICU                         
    ## Albumin_min                                 
    ## Bilirubin_max                               
    ## BUN_max                                  ***
    ## GCS_max                                  ** 
    ## HR_max                                   .  
    ## Lactate_max                                 
    ## Na_min                                   .  
    ## pH_min                                      
    ## Temp_min                                 .  
    ## Urine_min                                   
    ## WBC_min                                  *  
    ## WBC_max                                  *  
    ## Age:ICUTypeCardiac Surgery Recovery Unit    
    ## Age:ICUTypeMedical ICU                      
    ## Age:ICUTypeSurgical ICU                     
    ## Age:Albumin_min                             
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## (Dispersion parameter for binomial family taken to be 1)
    ## 
    ##     Null deviance: 307.90  on 298  degrees of freedom
    ## Residual deviance: 215.99  on 278  degrees of freedom
    ##   (1762 observations deleted due to missingness)
    ## AIC: 257.99
    ## 
    ## Number of Fisher Scoring iterations: 6
    # when using the predictors from our final df1 model with interactions onto df0 data
    # 1762 observations of data is removed due to missingness
    # the AIC is very low 253 - less data = easier to predict?
    
    summary(finalICU_glm)
    ## 
    ## Call:
    ## glm(formula = in_hospital_death ~ Age + ICUType + Albumin_min + 
    ##     Bilirubin_max + BUN_max + GCS_max + HR_max + Lactate_max + 
    ##     Na_min + pH_min + Temp_min + Urine_min + WBC_min + WBC_max, 
    ##     family = "binomial", data = nm_icu_model_df1)
    ## 
    ## Deviance Residuals: 
    ##     Min       1Q   Median       3Q      Max  
    ## -1.9438  -0.5450  -0.3479  -0.1945   2.9904  
    ## 
    ## Coefficients:
    ##                                       Estimate Std. Error z value
    ## (Intercept)                          16.771564   6.180202   2.714
    ## Age                                   0.035748   0.005082   7.034
    ## ICUTypeCardiac Surgery Recovery Unit -1.107288   0.292041  -3.792
    ## ICUTypeMedical ICU                    0.138003   0.215368   0.641
    ## ICUTypeSurgical ICU                   0.123606   0.235752   0.524
    ## Albumin_min                          -0.330533   0.119828  -2.758
    ## Bilirubin_max                         0.048073   0.013358   3.599
    ## BUN_max                               0.017653   0.002894   6.101
    ## GCS_max                              -0.177828   0.021643  -8.217
    ## HR_max                                0.007771   0.003215   2.417
    ## Lactate_max                           0.062615   0.033026   1.896
    ## Na_min                               -0.038723   0.014114  -2.744
    ## pH_min                               -1.101299   0.756621  -1.456
    ## Temp_min                             -0.162389   0.078329  -2.073
    ## Urine_min                            -0.006031   0.002509  -2.404
    ## WBC_min                               0.072729   0.025587   2.842
    ## WBC_max                              -0.063857   0.021592  -2.957
    ##                                                  Pr(>|z|)    
    ## (Intercept)                                       0.00665 ** 
    ## Age                                      0.00000000000201 ***
    ## ICUTypeCardiac Surgery Recovery Unit              0.00015 ***
    ## ICUTypeMedical ICU                                0.52167    
    ## ICUTypeSurgical ICU                               0.60007    
    ## Albumin_min                                       0.00581 ** 
    ## Bilirubin_max                                     0.00032 ***
    ## BUN_max                                  0.00000000105685 ***
    ## GCS_max                              < 0.0000000000000002 ***
    ## HR_max                                            0.01564 *  
    ## Lactate_max                                       0.05797 .  
    ## Na_min                                            0.00608 ** 
    ## pH_min                                            0.14552    
    ## Temp_min                                          0.03816 *  
    ## Urine_min                                         0.01622 *  
    ## WBC_min                                           0.00448 ** 
    ## WBC_max                                           0.00310 ** 
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## (Dispersion parameter for binomial family taken to be 1)
    ## 
    ##     Null deviance: 1604.2  on 1914  degrees of freedom
    ## Residual deviance: 1277.1  on 1898  degrees of freedom
    ## AIC: 1311.1
    ## 
    ## Number of Fisher Scoring iterations: 6
    summary(finalICU_glm_interactions)
    ## 
    ## Call:
    ## glm(formula = in_hospital_death ~ Age + ICUType + Albumin_min + 
    ##     Bilirubin_max + BUN_max + GCS_max + HR_max + Lactate_max + 
    ##     Na_min + pH_min + Temp_min + Urine_min + WBC_min + WBC_max + 
    ##     Age:ICUType + Age:Albumin_min, family = "binomial", data = nm_icu_model_df1)
    ## 
    ## Deviance Residuals: 
    ##     Min       1Q   Median       3Q      Max  
    ## -1.9494  -0.5533  -0.3360  -0.1854   3.2388  
    ## 
    ## Coefficients:
    ##                                           Estimate Std. Error z value
    ## (Intercept)                              20.855206   6.365565   3.276
    ## Age                                      -0.018285   0.028752  -0.636
    ## ICUTypeCardiac Surgery Recovery Unit     -0.562192   1.733448  -0.324
    ## ICUTypeMedical ICU                       -0.243286   1.265623  -0.192
    ## ICUTypeSurgical ICU                      -2.505360   1.374546  -1.823
    ## Albumin_min                              -1.384342   0.567281  -2.440
    ## Bilirubin_max                             0.048779   0.013523   3.607
    ## BUN_max                                   0.018215   0.002902   6.276
    ## GCS_max                                  -0.178502   0.021748  -8.208
    ## HR_max                                    0.008056   0.003232   2.492
    ## Lactate_max                               0.062277   0.033295   1.870
    ## Na_min                                   -0.038919   0.014253  -2.731
    ## pH_min                                   -1.084124   0.737653  -1.470
    ## Temp_min                                 -0.172788   0.079499  -2.173
    ## Urine_min                                -0.006015   0.002511  -2.395
    ## WBC_min                                   0.074082   0.025771   2.875
    ## WBC_max                                  -0.065411   0.021751  -3.007
    ## Age:ICUTypeCardiac Surgery Recovery Unit -0.008024   0.023597  -0.340
    ## Age:ICUTypeMedical ICU                    0.004228   0.016843   0.251
    ## Age:ICUTypeSurgical ICU                   0.036583   0.018295   2.000
    ## Age:Albumin_min                           0.014994   0.007834   1.914
    ##                                                      Pr(>|z|)    
    ## (Intercept)                                           0.00105 ** 
    ## Age                                                   0.52480    
    ## ICUTypeCardiac Surgery Recovery Unit                  0.74570    
    ## ICUTypeMedical ICU                                    0.84756    
    ## ICUTypeSurgical ICU                                   0.06835 .  
    ## Albumin_min                                           0.01467 *  
    ## Bilirubin_max                                         0.00031 ***
    ## BUN_max                                  0.000000000347023992 ***
    ## GCS_max                                  0.000000000000000226 ***
    ## HR_max                                                0.01269 *  
    ## Lactate_max                                           0.06142 .  
    ## Na_min                                                0.00632 ** 
    ## pH_min                                                0.14164    
    ## Temp_min                                              0.02974 *  
    ## Urine_min                                             0.01660 *  
    ## WBC_min                                               0.00405 ** 
    ## WBC_max                                               0.00264 ** 
    ## Age:ICUTypeCardiac Surgery Recovery Unit              0.73383    
    ## Age:ICUTypeMedical ICU                                0.80181    
    ## Age:ICUTypeSurgical ICU                               0.04554 *  
    ## Age:Albumin_min                                       0.05563 .  
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## (Dispersion parameter for binomial family taken to be 1)
    ## 
    ##     Null deviance: 1604.2  on 1914  degrees of freedom
    ## Residual deviance: 1263.2  on 1894  degrees of freedom
    ## AIC: 1305.2
    ## 
    ## Number of Fisher Scoring iterations: 6
    # variables significant in finalICU_glm
      # Age
      # ICUTypeCardiac Surgery Recovery unit
      # Albumin_min
      # Bilirubin_max
      # BUN_max
      # GCS_max
      # HR_max
      # Na_min
      # Temp_min
      # Urine_min
      # WBC_min
      # WBC_max
    
    # variables significant in finalICU_glm_interactions
      # Albumin_min
      # Bilirubin_max
      # BUN_max
      # GCS_max
      # HR_max
      # Na_min
      # Temp_min
      # Urine_min
      # WBC_min
      # WBC_max
      # Age:ICUTypeSurgicalICU
    
    # variables significant in df0_finalICU_glm_interactions
      # BUN_max
      # GCS_max
      # WBC_min
      # WBC_max
    
    # many of the variables that were significant in the imputed data model, are not significant when fitted to the df0 unimputated data
    # more missing variables = less power to produce a statistically significant result

    Final paragraph - summarising the most important findings of your final model & diagnostics. Include the most important values from the statistical output, and a simple clinical interpretation. - ?explain why not poisson - explain what we see when fitting to df0 ***

    Task 2 (15 marks)

    In this task, you are required to develop a Cox proportional hazards survival model using the icu_patients_df1 data set which adequately explains or predicts the length of survival indicated by the Days variable, with censoring as indicated by the Status variable. You should fit a series of models, maybe three or four, evaluating each one, before you present your final model. Your final model should not include all the predictor variables, just a small subset of them, which you have selected based on statistical significance and/or background knowledge. Aim for between five and ten predictor variables (slightly more or fewer is OK). It is perfectly acceptable to include predictor variables in your final model which are not statistically significant, as long as you justify their inclusion on medical or physiological grounds (you will not be marked down if your medical justification is not exactly correct, but do you best). You should assess each model you consider for goodness of fit and other relevant statistics, and you should assess your final model for violations of assumptions and perform other diagnostics which you think are relevant (and modify the model if indicated, or at least comment on the possible impact of what your diagnostics show). Finally, re-fit your final model to the unimputed data frame (icu_patients_df0.rds) and comment on any differences you find.

    Hints

    1. Select an initial subset of explanatory variables that you will use to predict survival. Justify your choice.

    2. Conduct basic exploratory data analysis on your variables of choice.

    3. Fit appropriate univariate Cox proportional hazards models.

    4. Fit an appropriate series of multivariable Cox proportional hazards models, justifying your approach. Assess each model you consider for goodness of fit and other relevant statistics.

    5. Present your final model. Your final model should not include all the predictor variables, just a small subset of them, which you have selected based on statistical significance and/or background knowledge.

    6. For your final model, present a set of diagnostic statistics and/or charts and comment on them.

    7. Write a very brief paragraph summarising the most important findings of your final model. Include the most important values from the statistical output, and a simple clinical interpretation.

    Task 2 Response:

    Select an initial subset of explanatory variables:

    The purpose of this task is to understand the impact of information collected during the first 24 hours of an ICU stay on the length of survival of the ICU population (followed up for 2408 days, approximately 6.5 years).

    To select an initial subset of explanatory variables, we used the same clinical logic as for Task 1 - to examine the measures used in already validated risk scores: SAPS1, SOFA and APACHE scores.

    Therefore, the initial subset of explanatory variables we have chosen for this task are:

    DEMOGRAPHIC VARIABLES:
    * Age
    * Gender
    * ICUType
    * Height
    * Weight_max

    CLINICAL VARIABLES:
    * Albumin_min
    * Bilirubin_max
    * BUN_max
    * Creatinine_max

    * GCS_min
    * Glucose_min and Glucose_max
    * HCO3_min
    * HR_min and HR_max
    * K_min and K_max
    * Lactate_max
    * MAP_min
    * Na_min and Na_max
    * NISysABP_min and NISysABP_max
    * Platelets_min
    * FiO2_max and PaO2_min - included as PFratio= PaO2_min/ FiO2_max
    * pH_min and pH_max
    * RespRate_min and RespRate_max
    * Temp_min and Temp_max
    * TroponinI_max
    * TroponinT_max
    * Urine_min
    * WBC_min and WBC_max

    Basic initial exploratory data analysis (EDA) and non-parametric survival curves:

    # Outcome variables
    unique_icu = unique(subset(icu_patients_df1, select = c(RecordID)))
    dim(unique_icu) # There are 2061 unique individuals
    ## [1] 2061    1
    table(icu_patients_df1$Status) #773 censored out of 2061 observations
    ## 
    ## FALSE  TRUE 
    ##  1288   773
    # Plot KM survival curve (non-parametric)
    ICU.fit <- survfit( Surv(Days, Status) ~ 1, data = icu_patients_df1) 
    print(ICU.fit, print.rmean = TRUE)
    ## Call: survfit(formula = Surv(Days, Status) ~ 1, data = icu_patients_df1)
    ## 
    ##          n     events     *rmean *se(rmean)     median    0.95LCL    0.95UCL 
    ##     2061.0      773.0     1633.5       23.1         NA         NA         NA 
    ##     * restricted mean with upper limit =  2408
    #summary(ICU.fit)
    plot(ICU.fit, main = 'Kaplan-Meier estimate of survival function', xlab = 'Length of survival (in days)')

    # plotting Nelson-Aalen estimate (non-parametric)
    plot(ICU.fit, fun="cumhaz", main = "Nelson-Aalen estimate of cumulative hazard function", xlab = 'Length of survival (in days)')

    There were 773 deaths (out of 2061 participants) during follow-up.The median follow-up time cannot be determined as the survival rate has not yet dropped to 50% survival at the end of the available data. The cumulative hazard rate (as shown in the Nelson Aalen plot) reaches 47% by the end of the available data.

    # Display frequencies for categorical explanatory variables
    table(icu_patients_df1$Gender)
    ## 
    ## Female   Male 
    ##    913   1148
    table(icu_patients_df1$ICUType)
    ## 
    ##            Coronary Care Unit Cardiac Surgery Recovery Unit 
    ##                           297                           448 
    ##                   Medical ICU                  Surgical ICU 
    ##                           788                           528
    # Display counts, histograms, median and IQRs for continuous explanatory variables
    
    # Create PFratio variable:
    icu_patients_df1$PFratio<-icu_patients_df1$PaO2_min/icu_patients_df1$FiO2_max
    
    # Write a function for continuous variable EDA output
    cont_eda <- function(variable){
        print(paste(variable,'EDA:'))
      
        na_rm <- na.omit(icu_patients_df1[,variable])
        print(paste('Number of non-missing values:',length(na_rm))) # number of non-missing values
        print(paste('Number of missing values:',sum(is.na(icu_patients_df1[,variable])))) # number of missing values
      
        print(quantile(icu_patients_df1[,variable], na.rm=TRUE))
        hist(icu_patients_df1[,variable], breaks=20, xlab=variable, main=paste('Histogram of',variable))
    }
    
    # Loop through the continuous variables from the chosen list of variables to explore and pass them to the EDA function
     cont_vars <- c('Age', 'Height', 'Weight_max', 'Albumin_min', 'Bilirubin_max', 
                    'BUN_max', 'Creatinine_max', 'GCS_min', 'Glucose_min', 
                    'Glucose_max', 'HCO3_min', 'HR_min', 'HR_max', 'K_min', 'K_max', 
                    'Lactate_max', 'MAP_min', 'Na_min', 'Na_max', 'NISysABP_min', 
                    'NISysABP_max', 'Platelets_min', 'PFratio', 'pH_min', 'pH_max', 
                    'RespRate_min', 'RespRate_max', 'Temp_min', 'Temp_max', 
                    'TroponinI_max', 'TroponinT_max', 'Urine_min', 'WBC_min', 'WBC_max')
    
    par(mfrow=c(12,3)) # set the layout of the histograms in 12 row x 3 column grid
    for(i in 1:length(cont_vars)){
      cont_eda(cont_vars[i])
    }
    ## [1] "Age EDA:"
    ## [1] "Number of non-missing values: 2061"
    ## [1] "Number of missing values: 0"
    ##   0%  25%  50%  75% 100% 
    ##   16   52   67   78   90
    ## [1] "Height EDA:"
    ## [1] "Number of non-missing values: 1069"
    ## [1] "Number of missing values: 992"
    ##    0%   25%   50%   75%  100% 
    ##  13.0 162.6 170.2 177.8 426.7
    ## [1] "Weight_max EDA:"
    ## [1] "Number of non-missing values: 1915"
    ## [1] "Number of missing values: 146"
    ##     0%    25%    50%    75%   100% 
    ##  34.60  66.00  80.00  94.55 230.00
    ## [1] "Albumin_min EDA:"
    ## [1] "Number of non-missing values: 2061"
    ## [1] "Number of missing values: 0"
    ##   0%  25%  50%  75% 100% 
    ##  1.1  2.6  3.0  3.5  5.3
    ## [1] "Bilirubin_max EDA:"
    ## [1] "Number of non-missing values: 2061"
    ## [1] "Number of missing values: 0"
    ##   0%  25%  50%  75% 100% 
    ##  0.1  0.4  0.7  1.3 45.9
    ## [1] "BUN_max EDA:"
    ## [1] "Number of non-missing values: 2061"
    ## [1] "Number of missing values: 0"
    ##   0%  25%  50%  75% 100% 
    ##    3   14   20   33  197
    ## [1] "Creatinine_max EDA:"
    ## [1] "Number of non-missing values: 2061"
    ## [1] "Number of missing values: 0"
    ##   0%  25%  50%  75% 100% 
    ##  0.2  0.8  1.0  1.5 22.0
    ## [1] "GCS_min EDA:"
    ## [1] "Number of non-missing values: 2061"
    ## [1] "Number of missing values: 0"
    ##   0%  25%  50%  75% 100% 
    ##    3    3    8   14   15
    ## [1] "Glucose_min EDA:"
    ## [1] "Number of non-missing values: 2061"
    ## [1] "Number of missing values: 0"
    ##   0%  25%  50%  75% 100% 
    ##   24   98  117  141  632
    ## [1] "Glucose_max EDA:"
    ## [1] "Number of non-missing values: 2061"
    ## [1] "Number of missing values: 0"
    ##   0%  25%  50%  75% 100% 
    ##   39  117  141  180 1143
    ## [1] "HCO3_min EDA:"
    ## [1] "Number of non-missing values: 2061"
    ## [1] "Number of missing values: 0"
    ##   0%  25%  50%  75% 100% 
    ##    5   20   23   25   44
    ## [1] "HR_min EDA:"
    ## [1] "Number of non-missing values: 2061"
    ## [1] "Number of missing values: 0"
    ##   0%  25%  50%  75% 100% 
    ##    0   61   71   81  126
    ## [1] "HR_max EDA:"
    ## [1] "Number of non-missing values: 2061"
    ## [1] "Number of missing values: 0"
    ##   0%  25%  50%  75% 100% 
    ##   44   91  104  119  300
    ## [1] "K_min EDA:"
    ## [1] "Number of non-missing values: 2061"
    ## [1] "Number of missing values: 0"
    ##   0%  25%  50%  75% 100% 
    ##  1.8  3.5  3.9  4.3  6.9
    ## [1] "K_max EDA:"
    ## [1] "Number of non-missing values: 2061"
    ## [1] "Number of missing values: 0"
    ##   0%  25%  50%  75% 100% 
    ##  2.5  4.0  4.3  4.7 22.9
    ## [1] "Lactate_max EDA:"
    ## [1] "Number of non-missing values: 2061"
    ## [1] "Number of missing values: 0"
    ##   0%  25%  50%  75% 100% 
    ##  0.4  1.5  2.2  3.2 29.3
    ## [1] "MAP_min EDA:"
    ## [1] "Number of non-missing values: 2061"
    ## [1] "Number of missing values: 0"
    ##   0%  25%  50%  75% 100% 
    ##    1   55   61   70  265
    ## [1] "Na_min EDA:"
    ## [1] "Number of non-missing values: 2061"
    ## [1] "Number of missing values: 0"
    ##   0%  25%  50%  75% 100% 
    ##   98  136  138  141  160
    ## [1] "Na_max EDA:"
    ## [1] "Number of non-missing values: 2061"
    ## [1] "Number of missing values: 0"
    ##   0%  25%  50%  75% 100% 
    ##  112  137  140  142  177
    ## [1] "NISysABP_min EDA:"
    ## [1] "Number of non-missing values: 1608"
    ## [1] "Number of missing values: 453"
    ##   0%  25%  50%  75% 100% 
    ##    4   83   95  108  234
    ## [1] "NISysABP_max EDA:"
    ## [1] "Number of non-missing values: 1608"
    ## [1] "Number of missing values: 453"
    ##   0%  25%  50%  75% 100% 
    ##   78  121  138  156  274
    ## [1] "Platelets_min EDA:"
    ## [1] "Number of non-missing values: 2061"
    ## [1] "Number of missing values: 0"
    ##   0%  25%  50%  75% 100% 
    ##    9  126  184  246  891
    ## [1] "PFratio EDA:"
    ## [1] "Number of non-missing values: 2061"
    ## [1] "Number of missing values: 0"
    ##   0%  25%  50%  75% 100% 
    ##   24   85  122  188 1150
    ## [1] "pH_min EDA:"
    ## [1] "Number of non-missing values: 2061"
    ## [1] "Number of missing values: 0"
    ##   0%  25%  50%  75% 100% 
    ## 3.00 7.28 7.34 7.39 7.63
    ## [1] "pH_max EDA:"
    ## [1] "Number of non-missing values: 2061"
    ## [1] "Number of missing values: 0"
    ##   0%  25%  50%  75% 100% 
    ## 7.15 7.38 7.42 7.46 7.69
    ## [1] "RespRate_min EDA:"
    ## [1] "Number of non-missing values: 2061"
    ## [1] "Number of missing values: 0"
    ##   0%  25%  50%  75% 100% 
    ##    4   12   14   17   24
    ## [1] "RespRate_max EDA:"
    ## [1] "Number of non-missing values: 2061"
    ## [1] "Number of missing values: 0"
    ##   0%  25%  50%  75% 100% 
    ##   13   24   27   33   98
    ## [1] "Temp_min EDA:"
    ## [1] "Number of non-missing values: 2061"
    ## [1] "Number of missing values: 0"
    ##   0%  25%  50%  75% 100% 
    ## 24.2 35.6 36.1 36.6 38.3
    ## [1] "Temp_max EDA:"
    ## [1] "Number of non-missing values: 2061"
    ## [1] "Number of missing values: 0"
    ##   0%  25%  50%  75% 100% 
    ## 35.4 37.1 37.6 38.2 42.1
    ## [1] "TroponinI_max EDA:"
    ## [1] "Number of non-missing values: 2061"
    ## [1] "Number of missing values: 0"
    ##   0%  25%  50%  75% 100% 
    ##  0.3  2.6  7.8 17.6 43.4
    ## [1] "TroponinT_max EDA:"
    ## [1] "Number of non-missing values: 2061"
    ## [1] "Number of missing values: 0"
    ##    0%   25%   50%   75%  100% 
    ##  0.01  0.06  0.17  0.80 24.46
    ## [1] "Urine_min EDA:"
    ## [1] "Number of non-missing values: 2061"
    ## [1] "Number of missing values: 0"
    ##   0%  25%  50%  75% 100% 
    ##    0    0   20   36  600
    ## [1] "WBC_min EDA:"
    ## [1] "Number of non-missing values: 2061"
    ## [1] "Number of missing values: 0"
    ##    0%   25%   50%   75%  100% 
    ##   0.1   7.6  10.4  14.1 128.3
    ## [1] "WBC_max EDA:"
    ## [1] "Number of non-missing values: 2061"
    ## [1] "Number of missing values: 0"
    ##    0%   25%   50%   75%  100% 
    ##   0.1   9.3  12.3  16.9 155.6

    EDA Findings:

    • There are 2061 unique individuals in the dataset. Of these, 913 are female (44%) and 1148 are male (56%).

    • Medical ICU accounted for 38% of individuals, 26% in Surgical ICU, 24% in Cardiac Surgery recovery Unit and 14% in the Coronary Care unit.

    • The following variables have a large proportion of missing observations:

      • Weight_max - 146 missing observations
      • Height - 992 missing observations
      • NISysABP_min & NISysABP_max - 453 missing observations
    • The median values (50% quantile) and IQR (25% - 75% quantiles) are displayed for all continuous variables.


    Deleted the commentary for median values - I think it is clear from the code output and doesn’t need additional explaining. ***

    #Plot the Kaplan-Meier survival curves by categorical variables in the data
    
    #Gender
    ICU.gender.fit <- survfit( Surv(Days, Status) ~ as.factor(Gender), data = icu_patients_df1) 
    print(ICU.gender.fit, print.rmean = TRUE)
    ## Call: survfit(formula = Surv(Days, Status) ~ as.factor(Gender), data = icu_patients_df1)
    ## 
    ##                             n events *rmean *se(rmean) median 0.95LCL 0.95UCL
    ## as.factor(Gender)=Female  913    364   1588       35.2     NA      NA      NA
    ## as.factor(Gender)=Male   1148    409   1670       30.6     NA      NA      NA
    ##     * restricted mean with upper limit =  2408
    plot(ICU.gender.fit, col=c("blue", "red"), main = 'Kaplan-Meier estimate of survival function', xlab = 'Length of survival (in days)')
    legend("bottomleft", legend=c("Female", "Male"),col=c("blue","red"), lty=1:1,cex=1)

    #ICUType
    ICU.type.fit <- survfit( Surv(Days, Status) ~ as.factor(ICUType), data = icu_patients_df1) 
    print(ICU.type.fit, print.rmean = TRUE)
    ## Call: survfit(formula = Surv(Days, Status) ~ as.factor(ICUType), data = icu_patients_df1)
    ## 
    ##                                                    n events *rmean *se(rmean)
    ## as.factor(ICUType)=Coronary Care Unit            297    132   1486       63.1
    ## as.factor(ICUType)=Cardiac Surgery Recovery Unit 448     99   2002       38.9
    ## as.factor(ICUType)=Medical ICU                   788    372   1414       39.3
    ## as.factor(ICUType)=Surgical ICU                  528    170   1731       44.3
    ##                                                  median 0.95LCL 0.95UCL
    ## as.factor(ICUType)=Coronary Care Unit                NA      NA      NA
    ## as.factor(ICUType)=Cardiac Surgery Recovery Unit     NA      NA      NA
    ## as.factor(ICUType)=Medical ICU                       NA    2051      NA
    ## as.factor(ICUType)=Surgical ICU                      NA      NA      NA
    ##     * restricted mean with upper limit =  2408
    plot(ICU.type.fit, col=c("blue", "red","purple","green"), main = 'Kaplan-Meier estimate of survival function', xlab = 'Length of survival (in days)')
    legend("bottomleft", legend=c("Coronary Care Unit", "Cardiac Surgery Recovery Unit", "Medical ICU", "Surgical ICU"),col=c("blue","red","purple","green"), lty=1:1,cex=1)

    The survival curves above show that risk of mortality is greater for the ICU population that is female than those that are male. Furthermore, ICU population mortality by ICU Type is different - those in Medical ICU have the highest risk of mortality whereas those in Cardiac Surgery Recovery Unit have the lowest. Interestingly, the survival curves look parallel for each category indicating Cox proportional hazards model is an appropriate model for ICU related survival.

    Univariate Cox proportional hazards models:

    # Cox proportional models and Log Rank tests for the chosen variables
    # Survival object = Surv(Days, Status)
    
    # Gender
    ICU.fitbyGender <- coxph( Surv(Days, Status) ~ as.factor(Gender), data = icu_patients_df1) 
    summary(ICU.fitbyGender)
    ## Call:
    ## coxph(formula = Surv(Days, Status) ~ as.factor(Gender), data = icu_patients_df1)
    ## 
    ##   n= 2061, number of events= 773 
    ## 
    ##                           coef exp(coef) se(coef)      z Pr(>|z|)  
    ## as.factor(Gender)Male -0.13708   0.87190  0.07206 -1.902   0.0571 .
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ##                       exp(coef) exp(-coef) lower .95 upper .95
    ## as.factor(Gender)Male    0.8719      1.147    0.7571     1.004
    ## 
    ## Concordance= 0.516  (se = 0.009 )
    ## Likelihood ratio test= 3.61  on 1 df,   p=0.06
    ## Wald test            = 3.62  on 1 df,   p=0.06
    ## Score (logrank) test = 3.62  on 1 df,   p=0.06
    # ICU Type
    ICU.fitbytype <- coxph( Surv(Days, Status) ~ as.factor(ICUType), data = icu_patients_df1) 
    summary(ICU.fitbytype)
    ## Call:
    ## coxph(formula = Surv(Days, Status) ~ as.factor(ICUType), data = icu_patients_df1)
    ## 
    ##   n= 2061, number of events= 773 
    ## 
    ##                                                     coef exp(coef) se(coef)
    ## as.factor(ICUType)Cardiac Surgery Recovery Unit -0.87895   0.41522  0.13301
    ## as.factor(ICUType)Medical ICU                    0.09362   1.09815  0.10131
    ## as.factor(ICUType)Surgical ICU                  -0.39843   0.67137  0.11603
    ##                                                      z        Pr(>|z|)    
    ## as.factor(ICUType)Cardiac Surgery Recovery Unit -6.608 0.0000000000389 ***
    ## as.factor(ICUType)Medical ICU                    0.924        0.355437    
    ## as.factor(ICUType)Surgical ICU                  -3.434        0.000595 ***
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ##                                                 exp(coef) exp(-coef) lower .95
    ## as.factor(ICUType)Cardiac Surgery Recovery Unit    0.4152     2.4084    0.3199
    ## as.factor(ICUType)Medical ICU                      1.0981     0.9106    0.9004
    ## as.factor(ICUType)Surgical ICU                     0.6714     1.4895    0.5348
    ##                                                 upper .95
    ## as.factor(ICUType)Cardiac Surgery Recovery Unit    0.5389
    ## as.factor(ICUType)Medical ICU                      1.3394
    ## as.factor(ICUType)Surgical ICU                     0.8428
    ## 
    ## Concordance= 0.597  (se = 0.009 )
    ## Likelihood ratio test= 98.74  on 3 df,   p=<0.0000000000000002
    ## Wald test            = 87.96  on 3 df,   p=<0.0000000000000002
    ## Score (logrank) test = 93.02  on 3 df,   p=<0.0000000000000002
    # Age
    ICU.fitbyage <- coxph( Surv(Days, Status) ~ Age, data = icu_patients_df1) 
    summary(ICU.fitbyage)
    ## Call:
    ## coxph(formula = Surv(Days, Status) ~ Age, data = icu_patients_df1)
    ## 
    ##   n= 2061, number of events= 773 
    ## 
    ##        coef exp(coef) se(coef)     z            Pr(>|z|)    
    ## Age 0.03355   1.03412  0.00250 13.42 <0.0000000000000002 ***
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ##     exp(coef) exp(-coef) lower .95 upper .95
    ## Age     1.034      0.967     1.029     1.039
    ## 
    ## Concordance= 0.646  (se = 0.01 )
    ## Likelihood ratio test= 209.4  on 1 df,   p=<0.0000000000000002
    ## Wald test            = 180.1  on 1 df,   p=<0.0000000000000002
    ## Score (logrank) test = 187  on 1 df,   p=<0.0000000000000002
    # Height
    ICU.fitbyheight <- coxph( Surv(Days, Status) ~ Height, data = icu_patients_df1) 
    summary(ICU.fitbyheight)
    ## Call:
    ## coxph(formula = Surv(Days, Status) ~ Height, data = icu_patients_df1)
    ## 
    ##   n= 1069, number of events= 385 
    ##    (992 observations deleted due to missingness)
    ## 
    ##             coef exp(coef)  se(coef)      z Pr(>|z|)
    ## Height -0.003851  0.996156  0.002346 -1.642    0.101
    ## 
    ##        exp(coef) exp(-coef) lower .95 upper .95
    ## Height    0.9962      1.004    0.9916     1.001
    ## 
    ## Concordance= 0.541  (se = 0.015 )
    ## Likelihood ratio test= 2.7  on 1 df,   p=0.1
    ## Wald test            = 2.69  on 1 df,   p=0.1
    ## Score (logrank) test = 2.52  on 1 df,   p=0.1
    # Weight_max
    ICU.fitbyweightmax <- coxph( Surv(Days, Status) ~ Weight_max, data = icu_patients_df1) 
    summary(ICU.fitbyweightmax)
    ## Call:
    ## coxph(formula = Surv(Days, Status) ~ Weight_max, data = icu_patients_df1)
    ## 
    ##   n= 1915, number of events= 721 
    ##    (146 observations deleted due to missingness)
    ## 
    ##                 coef exp(coef)  se(coef)      z  Pr(>|z|)    
    ## Weight_max -0.007213  0.992813  0.001759 -4.101 0.0000411 ***
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ##            exp(coef) exp(-coef) lower .95 upper .95
    ## Weight_max    0.9928      1.007    0.9894    0.9962
    ## 
    ## Concordance= 0.56  (se = 0.011 )
    ## Likelihood ratio test= 17.9  on 1 df,   p=0.00002
    ## Wald test            = 16.82  on 1 df,   p=0.00004
    ## Score (logrank) test = 16.71  on 1 df,   p=0.00004
    # Albumin_min
    ICU.fitbyAlbuminmin <- coxph( Surv(Days, Status) ~ Albumin_min, data = icu_patients_df1) 
    summary(ICU.fitbyAlbuminmin)
    ## Call:
    ## coxph(formula = Surv(Days, Status) ~ Albumin_min, data = icu_patients_df1)
    ## 
    ##   n= 2061, number of events= 773 
    ## 
    ##                 coef exp(coef) se(coef)     z Pr(>|z|)    
    ## Albumin_min -0.22075   0.80192  0.05704 -3.87 0.000109 ***
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ##             exp(coef) exp(-coef) lower .95 upper .95
    ## Albumin_min    0.8019      1.247    0.7171    0.8968
    ## 
    ## Concordance= 0.54  (se = 0.011 )
    ## Likelihood ratio test= 15.02  on 1 df,   p=0.0001
    ## Wald test            = 14.98  on 1 df,   p=0.0001
    ## Score (logrank) test = 14.99  on 1 df,   p=0.0001
    # Bilirubin_max
    ICU.fitbyBilirubinmax <- coxph( Surv(Days, Status) ~ Bilirubin_max, data = icu_patients_df1) 
    summary(ICU.fitbyBilirubinmax)
    ## Call:
    ## coxph(formula = Surv(Days, Status) ~ Bilirubin_max, data = icu_patients_df1)
    ## 
    ##   n= 2061, number of events= 773 
    ## 
    ##                   coef exp(coef) se(coef)     z Pr(>|z|)    
    ## Bilirubin_max 0.025159  1.025478 0.007431 3.386  0.00071 ***
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ##               exp(coef) exp(-coef) lower .95 upper .95
    ## Bilirubin_max     1.025     0.9752     1.011     1.041
    ## 
    ## Concordance= 0.515  (se = 0.011 )
    ## Likelihood ratio test= 9.48  on 1 df,   p=0.002
    ## Wald test            = 11.46  on 1 df,   p=0.0007
    ## Score (logrank) test = 11.7  on 1 df,   p=0.0006
    # BUN_max
    ICU.fitbyBUNmax <- coxph( Surv(Days, Status) ~ BUN_max, data = icu_patients_df1) 
    summary(ICU.fitbyBUNmax)
    ## Call:
    ## coxph(formula = Surv(Days, Status) ~ BUN_max, data = icu_patients_df1)
    ## 
    ##   n= 2061, number of events= 773 
    ## 
    ##             coef exp(coef) se(coef)     z            Pr(>|z|)    
    ## BUN_max 0.015002  1.015115 0.001064 14.09 <0.0000000000000002 ***
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ##         exp(coef) exp(-coef) lower .95 upper .95
    ## BUN_max     1.015     0.9851     1.013     1.017
    ## 
    ## Concordance= 0.647  (se = 0.01 )
    ## Likelihood ratio test= 142.5  on 1 df,   p=<0.0000000000000002
    ## Wald test            = 198.6  on 1 df,   p=<0.0000000000000002
    ## Score (logrank) test = 207  on 1 df,   p=<0.0000000000000002
    # Creatinine_max
    ICU.fitbyCreatininemax <- coxph( Surv(Days, Status) ~ Creatinine_max, data = icu_patients_df1) 
    summary(ICU.fitbyCreatininemax)
    ## Call:
    ## coxph(formula = Surv(Days, Status) ~ Creatinine_max, data = icu_patients_df1)
    ## 
    ##   n= 2061, number of events= 773 
    ## 
    ##                   coef exp(coef) se(coef)    z        Pr(>|z|)    
    ## Creatinine_max 0.10152   1.10685  0.01467 6.92 0.0000000000045 ***
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ##                exp(coef) exp(-coef) lower .95 upper .95
    ## Creatinine_max     1.107     0.9035     1.075     1.139
    ## 
    ## Concordance= 0.594  (se = 0.011 )
    ## Likelihood ratio test= 35.11  on 1 df,   p=0.000000003
    ## Wald test            = 47.89  on 1 df,   p=0.000000000005
    ## Score (logrank) test = 48.54  on 1 df,   p=0.000000000003
    # GCS_min
    ICU.fitbyGCSmin <- coxph( Surv(Days, Status) ~ GCS_min, data = icu_patients_df1) 
    summary(ICU.fitbyGCSmin)
    ## Call:
    ## coxph(formula = Surv(Days, Status) ~ GCS_min, data = icu_patients_df1)
    ## 
    ##   n= 2061, number of events= 773 
    ## 
    ##             coef exp(coef) se(coef)     z Pr(>|z|)
    ## GCS_min 0.006052  1.006070 0.007324 0.826    0.409
    ## 
    ##         exp(coef) exp(-coef) lower .95 upper .95
    ## GCS_min     1.006      0.994    0.9917     1.021
    ## 
    ## Concordance= 0.501  (se = 0.01 )
    ## Likelihood ratio test= 0.68  on 1 df,   p=0.4
    ## Wald test            = 0.68  on 1 df,   p=0.4
    ## Score (logrank) test = 0.68  on 1 df,   p=0.4
    # Glucose - min & max
    ICU.fitbyGlucosemin <- coxph( Surv(Days, Status) ~ Glucose_min, data = icu_patients_df1) 
    summary(ICU.fitbyGlucosemin)
    ## Call:
    ## coxph(formula = Surv(Days, Status) ~ Glucose_min, data = icu_patients_df1)
    ## 
    ##   n= 2061, number of events= 773 
    ## 
    ##                  coef exp(coef)  se(coef)     z Pr(>|z|)  
    ## Glucose_min 0.0014076 1.0014086 0.0007477 1.883   0.0597 .
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ##             exp(coef) exp(-coef) lower .95 upper .95
    ## Glucose_min     1.001     0.9986    0.9999     1.003
    ## 
    ## Concordance= 0.508  (se = 0.011 )
    ## Likelihood ratio test= 3.31  on 1 df,   p=0.07
    ## Wald test            = 3.54  on 1 df,   p=0.06
    ## Score (logrank) test = 3.53  on 1 df,   p=0.06
    ICU.fitbyGlucosemax <- coxph( Surv(Days, Status) ~ Glucose_max, data = icu_patients_df1) 
    summary(ICU.fitbyGlucosemax)
    ## Call:
    ## coxph(formula = Surv(Days, Status) ~ Glucose_max, data = icu_patients_df1)
    ## 
    ##   n= 2061, number of events= 773 
    ## 
    ##                  coef exp(coef)  se(coef) z  Pr(>|z|)    
    ## Glucose_max 0.0012981 1.0012989 0.0003245 4 0.0000634 ***
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ##             exp(coef) exp(-coef) lower .95 upper .95
    ## Glucose_max     1.001     0.9987     1.001     1.002
    ## 
    ## Concordance= 0.547  (se = 0.011 )
    ## Likelihood ratio test= 13.2  on 1 df,   p=0.0003
    ## Wald test            = 16  on 1 df,   p=0.00006
    ## Score (logrank) test = 15.96  on 1 df,   p=0.00006
    # HCO3_min
    ICU.fitbyHCO3min <- coxph( Surv(Days, Status) ~ HCO3_min, data = icu_patients_df1) 
    summary(ICU.fitbyHCO3min)
    ## Call:
    ## coxph(formula = Surv(Days, Status) ~ HCO3_min, data = icu_patients_df1)
    ## 
    ##   n= 2061, number of events= 773 
    ## 
    ##               coef exp(coef)  se(coef)      z Pr(>|z|)  
    ## HCO3_min -0.017036  0.983108  0.008023 -2.123   0.0337 *
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ##          exp(coef) exp(-coef) lower .95 upper .95
    ## HCO3_min    0.9831      1.017    0.9678    0.9987
    ## 
    ## Concordance= 0.535  (se = 0.011 )
    ## Likelihood ratio test= 4.49  on 1 df,   p=0.03
    ## Wald test            = 4.51  on 1 df,   p=0.03
    ## Score (logrank) test = 4.5  on 1 df,   p=0.03
    # HR - min & max
    ICU.fitbyHRmin <- coxph( Surv(Days, Status) ~ HR_min, data = icu_patients_df1) 
    summary(ICU.fitbyHRmin)
    ## Call:
    ## coxph(formula = Surv(Days, Status) ~ HR_min, data = icu_patients_df1)
    ## 
    ##   n= 2061, number of events= 773 
    ## 
    ##              coef  exp(coef)   se(coef)      z Pr(>|z|)
    ## HR_min -0.0009841  0.9990164  0.0024165 -0.407    0.684
    ## 
    ##        exp(coef) exp(-coef) lower .95 upper .95
    ## HR_min     0.999      1.001    0.9943     1.004
    ## 
    ## Concordance= 0.498  (se = 0.011 )
    ## Likelihood ratio test= 0.17  on 1 df,   p=0.7
    ## Wald test            = 0.17  on 1 df,   p=0.7
    ## Score (logrank) test = 0.17  on 1 df,   p=0.7
    ICU.fitbyHRmax <- coxph( Surv(Days, Status) ~ HR_max, data = icu_patients_df1) 
    summary(ICU.fitbyHRmax)
    ## Call:
    ## coxph(formula = Surv(Days, Status) ~ HR_max, data = icu_patients_df1)
    ## 
    ##   n= 2061, number of events= 773 
    ## 
    ##            coef exp(coef) se(coef)     z Pr(>|z|)  
    ## HR_max 0.002779  1.002783 0.001648 1.687   0.0916 .
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ##        exp(coef) exp(-coef) lower .95 upper .95
    ## HR_max     1.003     0.9972    0.9996     1.006
    ## 
    ## Concordance= 0.515  (se = 0.011 )
    ## Likelihood ratio test= 2.79  on 1 df,   p=0.09
    ## Wald test            = 2.85  on 1 df,   p=0.09
    ## Score (logrank) test = 2.84  on 1 df,   p=0.09
    # K - min & max
    ICU.fitbyKmin <- coxph( Surv(Days, Status) ~ K_min, data = icu_patients_df1) 
    summary(ICU.fitbyKmin)
    ## Call:
    ## coxph(formula = Surv(Days, Status) ~ K_min, data = icu_patients_df1)
    ## 
    ##   n= 2061, number of events= 773 
    ## 
    ##          coef exp(coef) se(coef)     z Pr(>|z|)
    ## K_min 0.03906   1.03983  0.06125 0.638    0.524
    ## 
    ##       exp(coef) exp(-coef) lower .95 upper .95
    ## K_min      1.04     0.9617    0.9222     1.172
    ## 
    ## Concordance= 0.502  (se = 0.011 )
    ## Likelihood ratio test= 0.41  on 1 df,   p=0.5
    ## Wald test            = 0.41  on 1 df,   p=0.5
    ## Score (logrank) test = 0.41  on 1 df,   p=0.5
    ICU.fitbyKmax <- coxph( Surv(Days, Status) ~ K_max, data = icu_patients_df1) 
    summary(ICU.fitbyKmax)
    ## Call:
    ## coxph(formula = Surv(Days, Status) ~ K_max, data = icu_patients_df1)
    ## 
    ##   n= 2061, number of events= 773 
    ## 
    ##          coef exp(coef) se(coef)     z Pr(>|z|)  
    ## K_max 0.07306   1.07579  0.02958 2.469   0.0135 *
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ##       exp(coef) exp(-coef) lower .95 upper .95
    ## K_max     1.076     0.9295     1.015      1.14
    ## 
    ## Concordance= 0.527  (se = 0.011 )
    ## Likelihood ratio test= 4.81  on 1 df,   p=0.03
    ## Wald test            = 6.1  on 1 df,   p=0.01
    ## Score (logrank) test = 5.98  on 1 df,   p=0.01
    # Lactate_max
    ICU.fitbyLactatemax <- coxph( Surv(Days, Status) ~ Lactate_max, data = icu_patients_df1) 
    summary(ICU.fitbyLactatemax)
    ## Call:
    ## coxph(formula = Surv(Days, Status) ~ Lactate_max, data = icu_patients_df1)
    ## 
    ##   n= 2061, number of events= 773 
    ## 
    ##                coef exp(coef) se(coef)     z Pr(>|z|)    
    ## Lactate_max 0.05778   1.05948  0.01666 3.467 0.000526 ***
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ##             exp(coef) exp(-coef) lower .95 upper .95
    ## Lactate_max     1.059     0.9439     1.025     1.095
    ## 
    ## Concordance= 0.508  (se = 0.011 )
    ## Likelihood ratio test= 10.95  on 1 df,   p=0.0009
    ## Wald test            = 12.02  on 1 df,   p=0.0005
    ## Score (logrank) test = 12.03  on 1 df,   p=0.0005
    # MAP_min
    ICU.fitbyMAPmin <- coxph( Surv(Days, Status) ~ MAP_min, data = icu_patients_df1) 
    summary(ICU.fitbyMAPmin)
    ## Call:
    ## coxph(formula = Surv(Days, Status) ~ MAP_min, data = icu_patients_df1)
    ## 
    ##   n= 2061, number of events= 773 
    ## 
    ##              coef exp(coef)  se(coef)     z Pr(>|z|)  
    ## MAP_min -0.004744  0.995267  0.002326 -2.04   0.0414 *
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ##         exp(coef) exp(-coef) lower .95 upper .95
    ## MAP_min    0.9953      1.005    0.9907    0.9998
    ## 
    ## Concordance= 0.52  (se = 0.01 )
    ## Likelihood ratio test= 4.37  on 1 df,   p=0.04
    ## Wald test            = 4.16  on 1 df,   p=0.04
    ## Score (logrank) test = 4.07  on 1 df,   p=0.04
    # Na - min & max
    ICU.fitbyNamin <- coxph( Surv(Days, Status) ~ Na_min, data = icu_patients_df1) 
    summary(ICU.fitbyNamin)
    ## Call:
    ## coxph(formula = Surv(Days, Status) ~ Na_min, data = icu_patients_df1)
    ## 
    ##   n= 2061, number of events= 773 
    ## 
    ##             coef exp(coef)  se(coef)      z Pr(>|z|)   
    ## Na_min -0.021187  0.979036  0.007371 -2.875  0.00405 **
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ##        exp(coef) exp(-coef) lower .95 upper .95
    ## Na_min     0.979      1.021     0.965    0.9933
    ## 
    ## Concordance= 0.536  (se = 0.011 )
    ## Likelihood ratio test= 7.74  on 1 df,   p=0.005
    ## Wald test            = 8.26  on 1 df,   p=0.004
    ## Score (logrank) test = 8.16  on 1 df,   p=0.004
    ICU.fitbyNamax <- coxph( Surv(Days, Status) ~ Na_max, data = icu_patients_df1) 
    summary(ICU.fitbyNamax)
    ## Call:
    ## coxph(formula = Surv(Days, Status) ~ Na_max, data = icu_patients_df1)
    ## 
    ##   n= 2061, number of events= 773 
    ## 
    ##             coef exp(coef)  se(coef)      z Pr(>|z|)  
    ## Na_max -0.015698  0.984424  0.008287 -1.894   0.0582 .
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ##        exp(coef) exp(-coef) lower .95 upper .95
    ## Na_max    0.9844      1.016    0.9686     1.001
    ## 
    ## Concordance= 0.521  (se = 0.011 )
    ## Likelihood ratio test= 3.61  on 1 df,   p=0.06
    ## Wald test            = 3.59  on 1 df,   p=0.06
    ## Score (logrank) test = 3.57  on 1 df,   p=0.06
    # NISysABP - min & max
    ICU.fitbyNISysABPmin <- coxph( Surv(Days, Status) ~ NISysABP_min, data = icu_patients_df1) 
    summary(ICU.fitbyNISysABPmin)
    ## Call:
    ## coxph(formula = Surv(Days, Status) ~ NISysABP_min, data = icu_patients_df1)
    ## 
    ##   n= 1608, number of events= 651 
    ##    (453 observations deleted due to missingness)
    ## 
    ##                   coef exp(coef)  se(coef)      z Pr(>|z|)    
    ## NISysABP_min -0.007374  0.992653  0.001994 -3.699 0.000216 ***
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ##              exp(coef) exp(-coef) lower .95 upper .95
    ## NISysABP_min    0.9927      1.007    0.9888    0.9965
    ## 
    ## Concordance= 0.555  (se = 0.012 )
    ## Likelihood ratio test= 14  on 1 df,   p=0.0002
    ## Wald test            = 13.68  on 1 df,   p=0.0002
    ## Score (logrank) test = 13.54  on 1 df,   p=0.0002
    ICU.fitbyNISysABPmax <- coxph( Surv(Days, Status) ~ NISysABP_max, data = icu_patients_df1) 
    summary(ICU.fitbyNISysABPmax)
    ## Call:
    ## coxph(formula = Surv(Days, Status) ~ NISysABP_max, data = icu_patients_df1)
    ## 
    ##   n= 1608, number of events= 651 
    ##    (453 observations deleted due to missingness)
    ## 
    ##                  coef exp(coef) se(coef)     z Pr(>|z|)  
    ## NISysABP_max 0.003503  1.003509 0.001402 2.498   0.0125 *
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ##              exp(coef) exp(-coef) lower .95 upper .95
    ## NISysABP_max     1.004     0.9965     1.001     1.006
    ## 
    ## Concordance= 0.523  (se = 0.012 )
    ## Likelihood ratio test= 6.12  on 1 df,   p=0.01
    ## Wald test            = 6.24  on 1 df,   p=0.01
    ## Score (logrank) test = 6.24  on 1 df,   p=0.01
    # Platelets_min
    ICU.fitbyPlateletsmin <- coxph( Surv(Days, Status) ~ Platelets_min, data = icu_patients_df1) 
    summary(ICU.fitbyPlateletsmin)
    ## Call:
    ## coxph(formula = Surv(Days, Status) ~ Platelets_min, data = icu_patients_df1)
    ## 
    ##   n= 2061, number of events= 773 
    ## 
    ##                    coef exp(coef)  se(coef)     z Pr(>|z|)
    ## Platelets_min 0.0001735 1.0001735 0.0003440 0.504    0.614
    ## 
    ##               exp(coef) exp(-coef) lower .95 upper .95
    ## Platelets_min         1     0.9998    0.9995     1.001
    ## 
    ## Concordance= 0.499  (se = 0.011 )
    ## Likelihood ratio test= 0.25  on 1 df,   p=0.6
    ## Wald test            = 0.25  on 1 df,   p=0.6
    ## Score (logrank) test = 0.25  on 1 df,   p=0.6
    # PFratio (PaO2_min/FiO2_max)
    ICU.fitbyPFratio <- coxph( Surv(Days, Status) ~ PFratio, data = icu_patients_df1) 
    summary(ICU.fitbyPFratio)
    ## Call:
    ## coxph(formula = Surv(Days, Status) ~ PFratio, data = icu_patients_df1)
    ## 
    ##   n= 2061, number of events= 773 
    ## 
    ##               coef  exp(coef)   se(coef)     z Pr(>|z|)
    ## PFratio -0.0002469  0.9997531  0.0003579 -0.69     0.49
    ## 
    ##         exp(coef) exp(-coef) lower .95 upper .95
    ## PFratio    0.9998          1    0.9991         1
    ## 
    ## Concordance= 0.513  (se = 0.011 )
    ## Likelihood ratio test= 0.49  on 1 df,   p=0.5
    ## Wald test            = 0.48  on 1 df,   p=0.5
    ## Score (logrank) test = 0.48  on 1 df,   p=0.5
    # pH - min & max
    ICU.fitbypHmin <- coxph( Surv(Days, Status) ~ pH_min, data = icu_patients_df1) 
    summary(ICU.fitbypHmin)
    ## Call:
    ## coxph(formula = Surv(Days, Status) ~ pH_min, data = icu_patients_df1)
    ## 
    ##   n= 2061, number of events= 773 
    ## 
    ##           coef exp(coef) se(coef)      z Pr(>|z|)    
    ## pH_min -0.6668    0.5133   0.1717 -3.884 0.000103 ***
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ##        exp(coef) exp(-coef) lower .95 upper .95
    ## pH_min    0.5133      1.948    0.3667    0.7187
    ## 
    ## Concordance= 0.51  (se = 0.011 )
    ## Likelihood ratio test= 8.34  on 1 df,   p=0.004
    ## Wald test            = 15.09  on 1 df,   p=0.0001
    ## Score (logrank) test = 14.09  on 1 df,   p=0.0002
    ICU.fitbypHmax <- coxph( Surv(Days, Status) ~ pH_max, data = icu_patients_df1) 
    summary(ICU.fitbypHmax)
    ## Call:
    ## coxph(formula = Surv(Days, Status) ~ pH_max, data = icu_patients_df1)
    ## 
    ##   n= 2061, number of events= 773 
    ## 
    ##           coef exp(coef) se(coef)      z Pr(>|z|)  
    ## pH_max -1.3288    0.2648   0.5512 -2.411   0.0159 *
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ##        exp(coef) exp(-coef) lower .95 upper .95
    ## pH_max    0.2648      3.776    0.0899      0.78
    ## 
    ## Concordance= 0.524  (se = 0.011 )
    ## Likelihood ratio test= 5.78  on 1 df,   p=0.02
    ## Wald test            = 5.81  on 1 df,   p=0.02
    ## Score (logrank) test = 5.81  on 1 df,   p=0.02
    # RespRate - min & max
    ICU.fitbyRespRatemin <- coxph( Surv(Days, Status) ~ RespRate_min, data = icu_patients_df1) 
    summary(ICU.fitbyRespRatemin)
    ## Call:
    ## coxph(formula = Surv(Days, Status) ~ RespRate_min, data = icu_patients_df1)
    ## 
    ##   n= 2061, number of events= 773 
    ## 
    ##                  coef exp(coef) se(coef)     z   Pr(>|z|)    
    ## RespRate_min 0.042945  1.043880 0.009451 4.544 0.00000552 ***
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ##              exp(coef) exp(-coef) lower .95 upper .95
    ## RespRate_min     1.044      0.958     1.025     1.063
    ## 
    ## Concordance= 0.555  (se = 0.01 )
    ## Likelihood ratio test= 20.44  on 1 df,   p=0.000006
    ## Wald test            = 20.65  on 1 df,   p=0.000006
    ## Score (logrank) test = 20.67  on 1 df,   p=0.000005
    ICU.fitbyRespRatemax <- coxph( Surv(Days, Status) ~ RespRate_max, data = icu_patients_df1) 
    summary(ICU.fitbyRespRatemax)
    ## Call:
    ## coxph(formula = Surv(Days, Status) ~ RespRate_max, data = icu_patients_df1)
    ## 
    ##   n= 2061, number of events= 773 
    ## 
    ##                 coef exp(coef) se(coef)     z Pr(>|z|)    
    ## RespRate_max 0.01472   1.01483  0.00432 3.407 0.000657 ***
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ##              exp(coef) exp(-coef) lower .95 upper .95
    ## RespRate_max     1.015     0.9854     1.006     1.023
    ## 
    ## Concordance= 0.535  (se = 0.011 )
    ## Likelihood ratio test= 10.93  on 1 df,   p=0.0009
    ## Wald test            = 11.61  on 1 df,   p=0.0007
    ## Score (logrank) test = 11.54  on 1 df,   p=0.0007
    # Temp - min & max
    ICU.fitbyTempmin <- coxph( Surv(Days, Status) ~ Temp_min, data = icu_patients_df1) 
    summary(ICU.fitbyTempmin)
    ## Call:
    ## coxph(formula = Surv(Days, Status) ~ Temp_min, data = icu_patients_df1)
    ## 
    ##   n= 2061, number of events= 773 
    ## 
    ##              coef exp(coef) se(coef)      z Pr(>|z|)   
    ## Temp_min -0.10541   0.89996  0.03894 -2.707  0.00679 **
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ##          exp(coef) exp(-coef) lower .95 upper .95
    ## Temp_min       0.9      1.111    0.8338    0.9713
    ## 
    ## Concordance= 0.528  (se = 0.011 )
    ## Likelihood ratio test= 6.85  on 1 df,   p=0.009
    ## Wald test            = 7.33  on 1 df,   p=0.007
    ## Score (logrank) test = 7.21  on 1 df,   p=0.007
    ICU.fitbyTempmax <- coxph( Surv(Days, Status) ~ Temp_max, data = icu_patients_df1) 
    summary(ICU.fitbyTempmax)
    ## Call:
    ## coxph(formula = Surv(Days, Status) ~ Temp_max, data = icu_patients_df1)
    ## 
    ##   n= 2061, number of events= 773 
    ## 
    ##             coef exp(coef) se(coef)      z  Pr(>|z|)    
    ## Temp_max -0.1966    0.8215   0.0493 -3.988 0.0000668 ***
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ##          exp(coef) exp(-coef) lower .95 upper .95
    ## Temp_max    0.8215      1.217    0.7459    0.9049
    ## 
    ## Concordance= 0.55  (se = 0.011 )
    ## Likelihood ratio test= 16.34  on 1 df,   p=0.00005
    ## Wald test            = 15.9  on 1 df,   p=0.00007
    ## Score (logrank) test = 15.89  on 1 df,   p=0.00007
    # Troponin_max (I and T assays)
    ICU.fitbyTroponinImax <- coxph( Surv(Days, Status) ~ TroponinI_max, data = icu_patients_df1) 
    summary(ICU.fitbyTroponinImax)
    ## Call:
    ## coxph(formula = Surv(Days, Status) ~ TroponinI_max, data = icu_patients_df1)
    ## 
    ##   n= 2061, number of events= 773 
    ## 
    ##                      coef   exp(coef)    se(coef)      z Pr(>|z|)
    ## TroponinI_max -0.00000905  0.99999095  0.00324098 -0.003    0.998
    ## 
    ##               exp(coef) exp(-coef) lower .95 upper .95
    ## TroponinI_max         1          1    0.9937     1.006
    ## 
    ## Concordance= 0.508  (se = 0.011 )
    ## Likelihood ratio test= 0  on 1 df,   p=1
    ## Wald test            = 0  on 1 df,   p=1
    ## Score (logrank) test = 0  on 1 df,   p=1
    ICU.fitbyTroponinTmax <- coxph( Surv(Days, Status) ~ TroponinT_max, data = icu_patients_df1) 
    summary(ICU.fitbyTroponinTmax)
    ## Call:
    ## coxph(formula = Surv(Days, Status) ~ TroponinT_max, data = icu_patients_df1)
    ## 
    ##   n= 2061, number of events= 773 
    ## 
    ##                  coef exp(coef) se(coef)     z Pr(>|z|)   
    ## TroponinT_max 0.04152   1.04239  0.01583 2.623  0.00871 **
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ##               exp(coef) exp(-coef) lower .95 upper .95
    ## TroponinT_max     1.042     0.9593     1.011     1.075
    ## 
    ## Concordance= 0.525  (se = 0.01 )
    ## Likelihood ratio test= 6  on 1 df,   p=0.01
    ## Wald test            = 6.88  on 1 df,   p=0.009
    ## Score (logrank) test = 6.89  on 1 df,   p=0.009
    # Urine_min
    ICU.fitbyUrinemin <- coxph( Surv(Days, Status) ~ Urine_min, data = icu_patients_df1) 
    summary(ICU.fitbyUrinemin)
    ## Call:
    ## coxph(formula = Surv(Days, Status) ~ Urine_min, data = icu_patients_df1)
    ## 
    ##   n= 2061, number of events= 773 
    ## 
    ##                 coef  exp(coef)   se(coef)      z Pr(>|z|)   
    ## Urine_min -0.0019252  0.9980767  0.0007179 -2.682  0.00733 **
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ##           exp(coef) exp(-coef) lower .95 upper .95
    ## Urine_min    0.9981      1.002    0.9967    0.9995
    ## 
    ## Concordance= 0.525  (se = 0.01 )
    ## Likelihood ratio test= 8.51  on 1 df,   p=0.004
    ## Wald test            = 7.19  on 1 df,   p=0.007
    ## Score (logrank) test = 7.23  on 1 df,   p=0.007
    # WBC - min & max
    ICU.fitbyWBCmin <- coxph( Surv(Days, Status) ~ WBC_min, data = icu_patients_df1) 
    summary(ICU.fitbyWBCmin)
    ## Call:
    ## coxph(formula = Surv(Days, Status) ~ WBC_min, data = icu_patients_df1)
    ## 
    ##   n= 2061, number of events= 773 
    ## 
    ##             coef exp(coef) se(coef)     z Pr(>|z|)  
    ## WBC_min 0.009102  1.009144 0.004755 1.914   0.0556 .
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ##         exp(coef) exp(-coef) lower .95 upper .95
    ## WBC_min     1.009     0.9909    0.9998     1.019
    ## 
    ## Concordance= 0.501  (se = 0.011 )
    ## Likelihood ratio test= 3.18  on 1 df,   p=0.07
    ## Wald test            = 3.66  on 1 df,   p=0.06
    ## Score (logrank) test = 3.59  on 1 df,   p=0.06
    ICU.fitbyWBCmax <- coxph( Surv(Days, Status) ~ WBC_max, data = icu_patients_df1) 
    summary(ICU.fitbyWBCmax)
    ## Call:
    ## coxph(formula = Surv(Days, Status) ~ WBC_max, data = icu_patients_df1)
    ## 
    ##   n= 2061, number of events= 773 
    ## 
    ##             coef exp(coef) se(coef)     z Pr(>|z|)
    ## WBC_max 0.003928  1.003936 0.004294 0.915     0.36
    ## 
    ##         exp(coef) exp(-coef) lower .95 upper .95
    ## WBC_max     1.004     0.9961    0.9955     1.012
    ## 
    ## Concordance= 0.491  (se = 0.011 )
    ## Likelihood ratio test= 0.79  on 1 df,   p=0.4
    ## Wald test            = 0.84  on 1 df,   p=0.4
    ## Score (logrank) test = 0.83  on 1 df,   p=0.4

    Univariable Cox model interpretation by Variable:

    • Gender - non-significant log-rank test (p-value = 0.06), means that the null hypothesis of no difference in survival between genders is not rejected with a conclusion that survival does not significantly differ by gender.

    • ICUType - significant log-rank test (p-value close to 0), means that the null hypothesis is rejected with a conclusion that survival significantly differs by each ICU Type. Note that, hazard rate for those in Medical ICU is not statistically significantly different for those in Coronary Care Unit.

    • Age - significant log-rank test (p-value close to 0), means that the null hypothesis is rejected with a conclusion that survival significantly differs by individual’s age. For every year older in age, the risk of mortality increases by approximately 3%.

    • Height - non-significant log-rank test (p-value = 0.1), means that the null hypothesis of no difference in survival for varying heights is not rejected with a conclusion that survival does not significantly differ by height.

    • Weight_max - significant log-rank test (p-value = 0.00004) indicating that the null hypothesis is rejected with a conclusion that survival significantly differs by weight. For every additional kilogram, the risk of mortality reduces by approximately 1%. The use of a centered variable may make it easier to interpret.

    • Clinical measures where the log-rank test results in a rejection of the null hypothesis (p-value <0.05) arguing for the variables’ significance in predicting survival times are:

      • Albumin_min
      • Bilirubin_max
      • Creatinine
      • BUN_max
      • Creatinine_max
      • Glucose_max
      • HCO3_min
      • K_max
      • Lactate_max
      • MAP_min
      • Na_min
      • NISysABP_min & NISysABP_max
      • pH_min & pH_max
      • RespRate_min & RespRate_max
      • Temp_min & Temp_max
      • TroponinT_max
      • Urine_min

    Multivariable Cox proportional hazards models:

    ## As in Task 1, create a dataset without missing or invalid data to use to build the model ##
    ## in order to remain consistent and allow comparisons between models to be made ##
    
    
     # Check counts of missing data in each variable
     for(i in 1:length(colnames(icu_patients_df1))){
       print(c(i,colnames(icu_patients_df1[i]), sum(is.na(icu_patients_df1[i]))))
     }
    ## [1] "1"        "RecordID" "0"       
    ## [1] "2"              "Length_of_stay" "0"             
    ## [1] "3"     "SAPS1" "96"   
    ## [1] "4"    "SOFA" "0"   
    ## [1] "5"        "Survival" "1288"    
    ## [1] "6"                 "in_hospital_death" "0"                
    ## [1] "7"    "Days" "0"   
    ## [1] "8"      "Status" "0"     
    ## [1] "9"   "Age" "0"  
    ## [1] "10"           "Albumin_diff" "0"           
    ## [1] "11"          "Albumin_max" "0"          
    ## [1] "12"          "Albumin_min" "0"          
    ## [1] "13"       "ALP_diff" "0"       
    ## [1] "14"      "ALP_max" "0"      
    ## [1] "15"      "ALP_min" "0"      
    ## [1] "16"       "ALT_diff" "0"       
    ## [1] "17"      "ALT_max" "0"      
    ## [1] "18"      "ALT_min" "0"      
    ## [1] "19"       "AST_diff" "0"       
    ## [1] "20"      "AST_max" "0"      
    ## [1] "21"      "AST_min" "0"      
    ## [1] "22"             "Bilirubin_diff" "0"             
    ## [1] "23"            "Bilirubin_max" "0"            
    ## [1] "24"            "Bilirubin_min" "0"            
    ## [1] "25"       "BUN_diff" "0"       
    ## [1] "26"      "BUN_max" "0"      
    ## [1] "27"      "BUN_min" "0"      
    ## [1] "28"               "Cholesterol_diff" "0"               
    ## [1] "29"              "Cholesterol_max" "0"              
    ## [1] "30"              "Cholesterol_min" "0"              
    ## [1] "31"              "Creatinine_diff" "0"              
    ## [1] "32"             "Creatinine_max" "0"             
    ## [1] "33"             "Creatinine_min" "0"             
    ## [1] "34"           "DiasABP_diff" "715"         
    ## [1] "35"          "DiasABP_max" "715"        
    ## [1] "36"          "DiasABP_min" "715"        
    ## [1] "37"        "FiO2_diff" "0"        
    ## [1] "38"       "FiO2_max" "0"       
    ## [1] "39"       "FiO2_min" "0"       
    ## [1] "40"       "GCS_diff" "0"       
    ## [1] "41"      "GCS_max" "0"      
    ## [1] "42"      "GCS_min" "0"      
    ## [1] "43"     "Gender" "0"     
    ## [1] "44"           "Glucose_diff" "0"           
    ## [1] "45"          "Glucose_max" "0"          
    ## [1] "46"          "Glucose_min" "0"          
    ## [1] "47"        "HCO3_diff" "0"        
    ## [1] "48"       "HCO3_max" "0"       
    ## [1] "49"       "HCO3_min" "0"       
    ## [1] "50"       "HCT_diff" "0"       
    ## [1] "51"      "HCT_max" "0"      
    ## [1] "52"      "HCT_min" "0"      
    ## [1] "53"     "Height" "992"   
    ## [1] "54"      "HR_diff" "0"      
    ## [1] "55"     "HR_max" "0"     
    ## [1] "56"     "HR_min" "0"     
    ## [1] "57"      "ICUType" "0"      
    ## [1] "58"     "K_diff" "0"     
    ## [1] "59"    "K_max" "0"    
    ## [1] "60"    "K_min" "0"    
    ## [1] "61"           "Lactate_diff" "0"           
    ## [1] "62"          "Lactate_max" "0"          
    ## [1] "63"          "Lactate_min" "0"          
    ## [1] "64"       "MAP_diff" "0"       
    ## [1] "65"      "MAP_max" "0"      
    ## [1] "66"      "MAP_min" "0"      
    ## [1] "67"      "Mg_diff" "0"      
    ## [1] "68"     "Mg_max" "0"     
    ## [1] "69"     "Mg_min" "0"     
    ## [1] "70"      "Na_diff" "0"      
    ## [1] "71"     "Na_max" "0"     
    ## [1] "72"     "Na_min" "0"     
    ## [1] "73"             "NIDiasABP_diff" "455"           
    ## [1] "74"            "NIDiasABP_max" "455"          
    ## [1] "75"            "NIDiasABP_min" "455"          
    ## [1] "76"         "NIMAP_diff" "455"       
    ## [1] "77"        "NIMAP_max" "455"      
    ## [1] "78"        "NIMAP_min" "455"      
    ## [1] "79"            "NISysABP_diff" "453"          
    ## [1] "80"           "NISysABP_max" "453"         
    ## [1] "81"           "NISysABP_min" "453"         
    ## [1] "82"         "PaCO2_diff" "0"         
    ## [1] "83"        "PaCO2_max" "0"        
    ## [1] "84"        "PaCO2_min" "0"        
    ## [1] "85"        "PaO2_diff" "0"        
    ## [1] "86"       "PaO2_max" "0"       
    ## [1] "87"       "PaO2_min" "0"       
    ## [1] "88"      "pH_diff" "0"      
    ## [1] "89"     "pH_max" "0"     
    ## [1] "90"     "pH_min" "0"     
    ## [1] "91"             "Platelets_diff" "0"             
    ## [1] "92"            "Platelets_max" "0"            
    ## [1] "93"            "Platelets_min" "0"            
    ## [1] "94"            "RespRate_diff" "0"            
    ## [1] "95"           "RespRate_max" "0"           
    ## [1] "96"           "RespRate_min" "0"           
    ## [1] "97"        "SaO2_diff" "0"        
    ## [1] "98"       "SaO2_max" "0"       
    ## [1] "99"       "SaO2_min" "0"       
    ## [1] "100"         "SysABP_diff" "715"        
    ## [1] "101"        "SysABP_max" "715"       
    ## [1] "102"        "SysABP_min" "715"       
    ## [1] "103"       "Temp_diff" "0"        
    ## [1] "104"      "Temp_max" "0"       
    ## [1] "105"      "Temp_min" "0"       
    ## [1] "106"            "TroponinI_diff" "0"             
    ## [1] "107"           "TroponinI_max" "0"            
    ## [1] "108"           "TroponinI_min" "0"            
    ## [1] "109"            "TroponinT_diff" "0"             
    ## [1] "110"           "TroponinT_max" "0"            
    ## [1] "111"           "TroponinT_min" "0"            
    ## [1] "112"        "Urine_diff" "0"         
    ## [1] "113"       "Urine_max" "0"        
    ## [1] "114"       "Urine_min" "0"        
    ## [1] "115"      "WBC_diff" "0"       
    ## [1] "116"     "WBC_max" "0"      
    ## [1] "117"     "WBC_min" "0"      
    ## [1] "118"         "Weight_diff" "146"        
    ## [1] "119"        "Weight_max" "146"       
    ## [1] "120"        "Weight_min" "146"       
    ## [1] "121"     "PFratio" "0"
     ## Result: of the variables chosen to explore for the survival model, large amounts of missing data in:
     ##         Height (992), NISysABP_min (453), NISysABP_max (453), Weight_max (146)
     
     ## Decision: include Weight_max; remove Height, NISysABP_min, NISysABP_max
     
     
     # Check counts of negative data (noted some -1 values) in each variable
     for(i in 1:length(colnames(icu_patients_df1))){
       print(c(i,colnames(icu_patients_df1[i]), sum(icu_patients_df1[i] < 0)))
     }
    ## [1] "1"        "RecordID" "0"       
    ## [1] "2"              "Length_of_stay" "25"            
    ## [1] "3"     "SAPS1" NA     
    ## [1] "4"    "SOFA" "65"  
    ## [1] "5"        "Survival" NA        
    ## [1] "6"                 "in_hospital_death" "0"                
    ## [1] "7"    "Days" "0"   
    ## [1] "8"      "Status" "0"     
    ## [1] "9"   "Age" "0"  
    ## [1] "10"           "Albumin_diff" "0"           
    ## [1] "11"          "Albumin_max" "0"          
    ## [1] "12"          "Albumin_min" "0"          
    ## [1] "13"       "ALP_diff" "0"       
    ## [1] "14"      "ALP_max" "0"      
    ## [1] "15"      "ALP_min" "0"      
    ## [1] "16"       "ALT_diff" "0"       
    ## [1] "17"      "ALT_max" "0"      
    ## [1] "18"      "ALT_min" "0"      
    ## [1] "19"       "AST_diff" "0"       
    ## [1] "20"      "AST_max" "0"      
    ## [1] "21"      "AST_min" "0"      
    ## [1] "22"             "Bilirubin_diff" "0"             
    ## [1] "23"            "Bilirubin_max" "0"            
    ## [1] "24"            "Bilirubin_min" "0"            
    ## [1] "25"       "BUN_diff" "0"       
    ## [1] "26"      "BUN_max" "0"      
    ## [1] "27"      "BUN_min" "0"      
    ## [1] "28"               "Cholesterol_diff" "0"               
    ## [1] "29"              "Cholesterol_max" "0"              
    ## [1] "30"              "Cholesterol_min" "0"              
    ## [1] "31"              "Creatinine_diff" "0"              
    ## [1] "32"             "Creatinine_max" "0"             
    ## [1] "33"             "Creatinine_min" "0"             
    ## [1] "34"           "DiasABP_diff" NA            
    ## [1] "35"          "DiasABP_max" NA           
    ## [1] "36"          "DiasABP_min" NA           
    ## [1] "37"        "FiO2_diff" "0"        
    ## [1] "38"       "FiO2_max" "0"       
    ## [1] "39"       "FiO2_min" "0"       
    ## [1] "40"       "GCS_diff" "0"       
    ## [1] "41"      "GCS_max" "0"      
    ## [1] "42"      "GCS_min" "0"
    ## Warning in Ops.factor(left, right): '<' not meaningful for factors
    ## [1] "43"     "Gender" NA      
    ## [1] "44"           "Glucose_diff" "0"           
    ## [1] "45"          "Glucose_max" "0"          
    ## [1] "46"          "Glucose_min" "0"          
    ## [1] "47"        "HCO3_diff" "0"        
    ## [1] "48"       "HCO3_max" "0"       
    ## [1] "49"       "HCO3_min" "0"       
    ## [1] "50"       "HCT_diff" "0"       
    ## [1] "51"      "HCT_max" "0"      
    ## [1] "52"      "HCT_min" "0"      
    ## [1] "53"     "Height" NA      
    ## [1] "54"      "HR_diff" "0"      
    ## [1] "55"     "HR_max" "0"     
    ## [1] "56"     "HR_min" "0"
    ## Warning in Ops.factor(left, right): '<' not meaningful for factors
    ## [1] "57"      "ICUType" NA       
    ## [1] "58"     "K_diff" "0"     
    ## [1] "59"    "K_max" "0"    
    ## [1] "60"    "K_min" "0"    
    ## [1] "61"           "Lactate_diff" "0"           
    ## [1] "62"          "Lactate_max" "0"          
    ## [1] "63"          "Lactate_min" "0"          
    ## [1] "64"       "MAP_diff" "0"       
    ## [1] "65"      "MAP_max" "0"      
    ## [1] "66"      "MAP_min" "0"      
    ## [1] "67"      "Mg_diff" "0"      
    ## [1] "68"     "Mg_max" "0"     
    ## [1] "69"     "Mg_min" "0"     
    ## [1] "70"      "Na_diff" "0"      
    ## [1] "71"     "Na_max" "0"     
    ## [1] "72"     "Na_min" "0"     
    ## [1] "73"             "NIDiasABP_diff" NA              
    ## [1] "74"            "NIDiasABP_max" NA             
    ## [1] "75"            "NIDiasABP_min" NA             
    ## [1] "76"         "NIMAP_diff" NA          
    ## [1] "77"        "NIMAP_max" NA         
    ## [1] "78"        "NIMAP_min" NA         
    ## [1] "79"            "NISysABP_diff" NA             
    ## [1] "80"           "NISysABP_max" NA            
    ## [1] "81"           "NISysABP_min" NA            
    ## [1] "82"         "PaCO2_diff" "0"         
    ## [1] "83"        "PaCO2_max" "0"        
    ## [1] "84"        "PaCO2_min" "0"        
    ## [1] "85"        "PaO2_diff" "0"        
    ## [1] "86"       "PaO2_max" "0"       
    ## [1] "87"       "PaO2_min" "0"       
    ## [1] "88"      "pH_diff" "0"      
    ## [1] "89"     "pH_max" "0"     
    ## [1] "90"     "pH_min" "0"     
    ## [1] "91"             "Platelets_diff" "0"             
    ## [1] "92"            "Platelets_max" "0"            
    ## [1] "93"            "Platelets_min" "0"            
    ## [1] "94"            "RespRate_diff" "0"            
    ## [1] "95"           "RespRate_max" "0"           
    ## [1] "96"           "RespRate_min" "0"           
    ## [1] "97"        "SaO2_diff" "0"        
    ## [1] "98"       "SaO2_max" "0"       
    ## [1] "99"       "SaO2_min" "0"       
    ## [1] "100"         "SysABP_diff" NA           
    ## [1] "101"        "SysABP_max" NA          
    ## [1] "102"        "SysABP_min" NA          
    ## [1] "103"       "Temp_diff" "0"        
    ## [1] "104"      "Temp_max" "0"       
    ## [1] "105"      "Temp_min" "0"       
    ## [1] "106"            "TroponinI_diff" "0"             
    ## [1] "107"           "TroponinI_max" "0"            
    ## [1] "108"           "TroponinI_min" "0"            
    ## [1] "109"            "TroponinT_diff" "0"             
    ## [1] "110"           "TroponinT_max" "0"            
    ## [1] "111"           "TroponinT_min" "0"            
    ## [1] "112"        "Urine_diff" "0"         
    ## [1] "113"       "Urine_max" "0"        
    ## [1] "114"       "Urine_min" "0"        
    ## [1] "115"      "WBC_diff" "0"       
    ## [1] "116"     "WBC_max" "0"      
    ## [1] "117"     "WBC_min" "0"      
    ## [1] "118"         "Weight_diff" NA           
    ## [1] "119"        "Weight_max" NA          
    ## [1] "120"        "Weight_min" NA          
    ## [1] "121"     "PFratio" "0"
     ## Result: negative values in Length_of_stay and SOFA (not listed in initial choice of variables anyway)
    
    
     # Create a new dataset with the only non-missing data from list of initial variables chosen
     # (excluding those with very high missingness i.e. Height, NISysABP_min, NISysABP_max)
     nm_icu_model_df1 <- na.omit(subset(icu_patients_df1, 
                                        select=c(Days, Status, # the survival object variables
                                                 RecordID, # keep record id for reference if needed
                                                 in_hospital_death, # from task 1
                                                 Age, Gender, ICUType, Weight_max,
                                                 Albumin_min, Bilirubin_max,
                                                 BUN_max, Creatinine_max, 
                                                 GCS_max, Glucose_min, Glucose_max, 
                                                 HCO3_min, HR_min, HR_max, K_min, 
                                                 K_max, Lactate_max, MAP_min, Na_min,
                                                 Na_max, Platelets_min, PFratio, pH_min,
                                                 pH_max, RespRate_min, RespRate_max,
                                                 Temp_min, Temp_max, TroponinT_max, 
                                                 TroponinI_max, Urine_min, WBC_min, WBC_max)))
    
    dim(nm_icu_model_df1)
    ## [1] 1915   37

    Due to the high degree of missingness, NISysABP_min, NISysABP_max and Height variables will be excluded from the multivariate modelling. After removing missing values, the resulting dataset used to fit multivariable models has 1915 observations.

    ## Fitting multivariable models ##
    
    
    # Create a function to calculate AIC
    calc_aic <- function(model){
      AIC <- 2*length(model$coefficients)-2*model$loglik[2]
    }
    
    
    # Full model using all listed initial variables (excluding those with high missingness)
    ICU.mv_full <- coxph(Surv(Days, Status) ~ 
                        Age + Gender + ICUType + Weight_max + Albumin_min + Bilirubin_max +
                        BUN_max + Creatinine_max + GCS_max + Glucose_min + Glucose_max + 
                        HCO3_min + HR_min + HR_max + K_min + K_max + Lactate_max + MAP_min + 
                        Na_min + Na_max + Platelets_min + PFratio + pH_min + pH_max + 
                        RespRate_min + RespRate_max + Temp_min + Temp_max + TroponinT_max + 
                        TroponinI_max + Urine_min + WBC_min + WBC_max,
                        data = nm_icu_model_df1)
    summary(ICU.mv_full)
    ## Call:
    ## coxph(formula = Surv(Days, Status) ~ Age + Gender + ICUType + 
    ##     Weight_max + Albumin_min + Bilirubin_max + BUN_max + Creatinine_max + 
    ##     GCS_max + Glucose_min + Glucose_max + HCO3_min + HR_min + 
    ##     HR_max + K_min + K_max + Lactate_max + MAP_min + Na_min + 
    ##     Na_max + Platelets_min + PFratio + pH_min + pH_max + RespRate_min + 
    ##     RespRate_max + Temp_min + Temp_max + TroponinT_max + TroponinI_max + 
    ##     Urine_min + WBC_min + WBC_max, data = nm_icu_model_df1)
    ## 
    ##   n= 1915, number of events= 721 
    ## 
    ##                                             coef   exp(coef)    se(coef)      z
    ## Age                                   0.03317420  1.03373060  0.00293981 11.284
    ## GenderMale                           -0.02592987  0.97440342  0.08213299 -0.316
    ## ICUTypeCardiac Surgery Recovery Unit -0.77268237  0.46177276  0.16528997 -4.675
    ## ICUTypeMedical ICU                    0.31563031  1.37112327  0.11800531  2.675
    ## ICUTypeSurgical ICU                  -0.02301483  0.97724799  0.13801760 -0.167
    ## Weight_max                           -0.00243670  0.99756627  0.00193453 -1.260
    ## Albumin_min                          -0.11881877  0.88796872  0.06628328 -1.793
    ## Bilirubin_max                         0.01439740  1.01450154  0.00797465  1.805
    ## BUN_max                               0.01130860  1.01137279  0.00201088  5.624
    ## Creatinine_max                       -0.01482676  0.98528261  0.02766417 -0.536
    ## GCS_max                              -0.10623594  0.89921246  0.01452209 -7.315
    ## Glucose_min                          -0.00023802  0.99976201  0.00094230 -0.253
    ## Glucose_max                           0.00044814  1.00044824  0.00056329  0.796
    ## HCO3_min                              0.01886028  1.01903926  0.00968401  1.948
    ## HR_min                                0.00591389  1.00593141  0.00306191  1.931
    ## HR_max                                0.00202173  1.00202378  0.00200232  1.010
    ## K_min                                 0.06929166  1.07174875  0.08175841  0.848
    ## K_max                                -0.03279543  0.96773651  0.04629908 -0.708
    ## Lactate_max                           0.04373789  1.04470849  0.02026084  2.159
    ## MAP_min                              -0.00084711  0.99915325  0.00243055 -0.349
    ## Na_min                               -0.00760018  0.99242863  0.01840942 -0.413
    ## Na_max                               -0.03029393  0.97016034  0.01857343 -1.631
    ## Platelets_min                        -0.00033177  0.99966828  0.00042555 -0.780
    ## PFratio                              -0.00001688  0.99998312  0.00039515 -0.043
    ## pH_min                               -0.48286560  0.61701274  0.20067709 -2.406
    ## pH_max                                0.40316049  1.49654705  0.67511086  0.597
    ## RespRate_min                         -0.01676745  0.98337235  0.01305267 -1.285
    ## RespRate_max                          0.00762531  1.00765446  0.00620645  1.229
    ## Temp_min                             -0.04991242  0.95131273  0.04838417 -1.032
    ## Temp_max                             -0.13691486  0.87204447  0.05738362 -2.386
    ## TroponinT_max                         0.01708332  1.01723007  0.01829875  0.934
    ## TroponinI_max                         0.00253724  1.00254046  0.00399639  0.635
    ## Urine_min                            -0.00197615  0.99802581  0.00096945 -2.038
    ## WBC_min                               0.02549144  1.02581913  0.01460170  1.746
    ## WBC_max                              -0.01991114  0.98028578  0.01203181 -1.655
    ##                                                  Pr(>|z|)    
    ## Age                                  < 0.0000000000000002 ***
    ## GenderMale                                        0.75223    
    ## ICUTypeCardiac Surgery Recovery Unit    0.000002943718242 ***
    ## ICUTypeMedical ICU                                0.00748 ** 
    ## ICUTypeSurgical ICU                               0.86756    
    ## Weight_max                                        0.20782    
    ## Albumin_min                                       0.07304 .  
    ## Bilirubin_max                                     0.07101 .  
    ## BUN_max                                 0.000000018688704 ***
    ## Creatinine_max                                    0.59199    
    ## GCS_max                                 0.000000000000256 ***
    ## Glucose_min                                       0.80058    
    ## Glucose_max                                       0.42628    
    ## HCO3_min                                          0.05147 .  
    ## HR_min                                            0.05343 .  
    ## HR_max                                            0.31264    
    ## K_min                                             0.39671    
    ## K_max                                             0.47873    
    ## Lactate_max                                       0.03087 *  
    ## MAP_min                                           0.72744    
    ## Na_min                                            0.67972    
    ## Na_max                                            0.10288    
    ## Platelets_min                                     0.43561    
    ## PFratio                                           0.96592    
    ## pH_min                                            0.01612 *  
    ## pH_max                                            0.55039    
    ## RespRate_min                                      0.19893    
    ## RespRate_max                                      0.21922    
    ## Temp_min                                          0.30227    
    ## Temp_max                                          0.01703 *  
    ## TroponinT_max                                     0.35052    
    ## TroponinI_max                                     0.52550    
    ## Urine_min                                         0.04151 *  
    ## WBC_min                                           0.08085 .  
    ## WBC_max                                           0.09795 .  
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ##                                      exp(coef) exp(-coef) lower .95 upper .95
    ## Age                                     1.0337     0.9674    1.0278    1.0397
    ## GenderMale                              0.9744     1.0263    0.8295    1.1446
    ## ICUTypeCardiac Surgery Recovery Unit    0.4618     2.1656    0.3340    0.6384
    ## ICUTypeMedical ICU                      1.3711     0.7293    1.0880    1.7279
    ## ICUTypeSurgical ICU                     0.9772     1.0233    0.7456    1.2808
    ## Weight_max                              0.9976     1.0024    0.9938    1.0014
    ## Albumin_min                             0.8880     1.1262    0.7798    1.0112
    ## Bilirubin_max                           1.0145     0.9857    0.9988    1.0305
    ## BUN_max                                 1.0114     0.9888    1.0074    1.0154
    ## Creatinine_max                          0.9853     1.0149    0.9333    1.0402
    ## GCS_max                                 0.8992     1.1121    0.8740    0.9252
    ## Glucose_min                             0.9998     1.0002    0.9979    1.0016
    ## Glucose_max                             1.0004     0.9996    0.9993    1.0016
    ## HCO3_min                                1.0190     0.9813    0.9999    1.0386
    ## HR_min                                  1.0059     0.9941    0.9999    1.0120
    ## HR_max                                  1.0020     0.9980    0.9981    1.0060
    ## K_min                                   1.0717     0.9331    0.9131    1.2580
    ## K_max                                   0.9677     1.0333    0.8838    1.0597
    ## Lactate_max                             1.0447     0.9572    1.0040    1.0870
    ## MAP_min                                 0.9992     1.0008    0.9944    1.0039
    ## Na_min                                  0.9924     1.0076    0.9573    1.0289
    ## Na_max                                  0.9702     1.0308    0.9355    1.0061
    ## Platelets_min                           0.9997     1.0003    0.9988    1.0005
    ## PFratio                                 1.0000     1.0000    0.9992    1.0008
    ## pH_min                                  0.6170     1.6207    0.4164    0.9143
    ## pH_max                                  1.4965     0.6682    0.3985    5.6201
    ## RespRate_min                            0.9834     1.0169    0.9585    1.0089
    ## RespRate_max                            1.0077     0.9924    0.9955    1.0200
    ## Temp_min                                0.9513     1.0512    0.8652    1.0459
    ## Temp_max                                0.8720     1.1467    0.7793    0.9759
    ## TroponinT_max                           1.0172     0.9831    0.9814    1.0544
    ## TroponinI_max                           1.0025     0.9975    0.9947    1.0104
    ## Urine_min                               0.9980     1.0020    0.9961    0.9999
    ## WBC_min                                 1.0258     0.9748    0.9969    1.0556
    ## WBC_max                                 0.9803     1.0201    0.9574    1.0037
    ## 
    ## Concordance= 0.743  (se = 0.009 )
    ## Likelihood ratio test= 518.5  on 35 df,   p=<0.0000000000000002
    ## Wald test            = 507.1  on 35 df,   p=<0.0000000000000002
    ## Score (logrank) test = 556  on 35 df,   p=<0.0000000000000002
    # Calculate full model AIC
    AIC.mv_full <- calc_aic(ICU.mv_full)
    AIC.mv_full #10136
    ## [1] 10135.95
    # 1st reduced model using all variables with significant log-rank tests
    ICU.mv_reduced1 <- coxph(Surv(Days, Status) ~
                            Age + ICUType + Weight_max + Albumin_min + Bilirubin_max +
                            BUN_max + Creatinine_max + Glucose_max + HCO3_min + 
                            K_max + Lactate_max + MAP_min + Na_min + pH_min + 
                            pH_max + RespRate_min + RespRate_max + Temp_min + 
                            Temp_max + TroponinT_max + Urine_min,
                            data = nm_icu_model_df1)
    summary(ICU.mv_reduced1)
    ## Call:
    ## coxph(formula = Surv(Days, Status) ~ Age + ICUType + Weight_max + 
    ##     Albumin_min + Bilirubin_max + BUN_max + Creatinine_max + 
    ##     Glucose_max + HCO3_min + K_max + Lactate_max + MAP_min + 
    ##     Na_min + pH_min + pH_max + RespRate_min + RespRate_max + 
    ##     Temp_min + Temp_max + TroponinT_max + Urine_min, data = nm_icu_model_df1)
    ## 
    ##   n= 1915, number of events= 721 
    ## 
    ##                                            coef  exp(coef)   se(coef)      z
    ## Age                                   0.0312354  1.0317284  0.0028364 11.012
    ## ICUTypeCardiac Surgery Recovery Unit -0.6478864  0.5231503  0.1526726 -4.244
    ## ICUTypeMedical ICU                    0.3901076  1.4771398  0.1174207  3.322
    ## ICUTypeSurgical ICU                   0.0838899  1.0875091  0.1335289  0.628
    ## Weight_max                           -0.0021849  0.9978175  0.0018229 -1.199
    ## Albumin_min                          -0.1540079  0.8572653  0.0645077 -2.387
    ## Bilirubin_max                         0.0144855  1.0145910  0.0081080  1.787
    ## BUN_max                               0.0123140  1.0123901  0.0019382  6.353
    ## Creatinine_max                       -0.0294390  0.9709901  0.0265352 -1.109
    ## Glucose_max                           0.0001531  1.0001531  0.0004043  0.379
    ## HCO3_min                              0.0174705  1.0176240  0.0092255  1.894
    ## K_max                                -0.0253362  0.9749821  0.0363475 -0.697
    ## Lactate_max                           0.0545008  1.0560134  0.0196475  2.774
    ## MAP_min                              -0.0012256  0.9987751  0.0023952 -0.512
    ## Na_min                               -0.0286393  0.9717669  0.0080801 -3.544
    ## pH_min                               -0.6275382  0.5339046  0.1968359 -3.188
    ## pH_max                                0.8969219  2.4520437  0.6400444  1.401
    ## RespRate_min                          0.0163537  1.0164882  0.0116422  1.405
    ## RespRate_max                          0.0124759  1.0125540  0.0056445  2.210
    ## Temp_min                             -0.0426614  0.9582358  0.0474244 -0.900
    ## Temp_max                             -0.0829817  0.9203680  0.0557570 -1.488
    ## TroponinT_max                         0.0168454  1.0169881  0.0175080  0.962
    ## Urine_min                            -0.0025723  0.9974311  0.0009526 -2.700
    ##                                                  Pr(>|z|)    
    ## Age                                  < 0.0000000000000002 ***
    ## ICUTypeCardiac Surgery Recovery Unit       0.000021992990 ***
    ## ICUTypeMedical ICU                               0.000893 ***
    ## ICUTypeSurgical ICU                              0.529838    
    ## Weight_max                                       0.230687    
    ## Albumin_min                                      0.016967 *  
    ## Bilirubin_max                                    0.074005 .  
    ## BUN_max                                    0.000000000211 ***
    ## Creatinine_max                                   0.267245    
    ## Glucose_max                                      0.704875    
    ## HCO3_min                                         0.058262 .  
    ## K_max                                            0.485769    
    ## Lactate_max                                      0.005538 ** 
    ## MAP_min                                          0.608865    
    ## Na_min                                           0.000393 ***
    ## pH_min                                           0.001432 ** 
    ## pH_max                                           0.161112    
    ## RespRate_min                                     0.160113    
    ## RespRate_max                                     0.027086 *  
    ## Temp_min                                         0.368351    
    ## Temp_max                                         0.136678    
    ## TroponinT_max                                    0.335972    
    ## Urine_min                                        0.006927 ** 
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ##                                      exp(coef) exp(-coef) lower .95 upper .95
    ## Age                                     1.0317     0.9692    1.0260    1.0375
    ## ICUTypeCardiac Surgery Recovery Unit    0.5232     1.9115    0.3879    0.7056
    ## ICUTypeMedical ICU                      1.4771     0.6770    1.1735    1.8594
    ## ICUTypeSurgical ICU                     1.0875     0.9195    0.8371    1.4128
    ## Weight_max                              0.9978     1.0022    0.9943    1.0014
    ## Albumin_min                             0.8573     1.1665    0.7555    0.9728
    ## Bilirubin_max                           1.0146     0.9856    0.9986    1.0308
    ## BUN_max                                 1.0124     0.9878    1.0086    1.0162
    ## Creatinine_max                          0.9710     1.0299    0.9218    1.0228
    ## Glucose_max                             1.0002     0.9998    0.9994    1.0009
    ## HCO3_min                                1.0176     0.9827    0.9994    1.0362
    ## K_max                                   0.9750     1.0257    0.9079    1.0470
    ## Lactate_max                             1.0560     0.9470    1.0161    1.0975
    ## MAP_min                                 0.9988     1.0012    0.9941    1.0035
    ## Na_min                                  0.9718     1.0291    0.9565    0.9873
    ## pH_min                                  0.5339     1.8730    0.3630    0.7853
    ## pH_max                                  2.4520     0.4078    0.6994    8.5968
    ## RespRate_min                            1.0165     0.9838    0.9936    1.0399
    ## RespRate_max                            1.0126     0.9876    1.0014    1.0238
    ## Temp_min                                0.9582     1.0436    0.8732    1.0516
    ## Temp_max                                0.9204     1.0865    0.8251    1.0266
    ## TroponinT_max                           1.0170     0.9833    0.9827    1.0525
    ## Urine_min                               0.9974     1.0026    0.9956    0.9993
    ## 
    ## Concordance= 0.726  (se = 0.009 )
    ## Likelihood ratio test= 452.1  on 23 df,   p=<0.0000000000000002
    ## Wald test            = 439.8  on 23 df,   p=<0.0000000000000002
    ## Score (logrank) test = 482.2  on 23 df,   p=<0.0000000000000002
    # Calculate 1st reduced model AIC
    AIC.mv_reduced1 <- calc_aic(ICU.mv_reduced1)
    AIC.mv_reduced1 #10178
    ## [1] 10178.32
    # 2nd reduced model using all variables significant (using cut off p < 0.1) in ICU.mv_reduced1
    # (note using p < 0.1 gained better results than p < 0.05 as a cut off)
    ICU.mv_reduced2 <- coxph(Surv(Days, Status) ~
                            Age + ICUType + Albumin_min + Bilirubin_max + BUN_max + 
                            HCO3_min + Lactate_max + Na_min + pH_min + 
                            RespRate_max + Urine_min,
                            data = nm_icu_model_df1)
    summary(ICU.mv_reduced2)
    ## Call:
    ## coxph(formula = Surv(Days, Status) ~ Age + ICUType + Albumin_min + 
    ##     Bilirubin_max + BUN_max + HCO3_min + Lactate_max + Na_min + 
    ##     pH_min + RespRate_max + Urine_min, data = nm_icu_model_df1)
    ## 
    ##   n= 1915, number of events= 721 
    ## 
    ##                                            coef  exp(coef)   se(coef)      z
    ## Age                                   0.0336951  1.0342693  0.0026779 12.583
    ## ICUTypeCardiac Surgery Recovery Unit -0.7052417  0.4939891  0.1428496 -4.937
    ## ICUTypeMedical ICU                    0.3140214  1.3689190  0.1113657  2.820
    ## ICUTypeSurgical ICU                   0.0067186  1.0067412  0.1273610  0.053
    ## Albumin_min                          -0.1529698  0.8581556  0.0634725 -2.410
    ## Bilirubin_max                         0.0146272  1.0147347  0.0079423  1.842
    ## BUN_max                               0.0106532  1.0107102  0.0014018  7.600
    ## HCO3_min                              0.0173644  1.0175161  0.0087596  1.982
    ## Lactate_max                           0.0628071  1.0648214  0.0182291  3.445
    ## Na_min                               -0.0252732  0.9750435  0.0073066 -3.459
    ## pH_min                               -0.6409326  0.5268009  0.1946101 -3.293
    ## RespRate_max                          0.0143032  1.0144059  0.0047394  3.018
    ## Urine_min                            -0.0025693  0.9974340  0.0009383 -2.738
    ##                                                  Pr(>|z|)    
    ## Age                                  < 0.0000000000000002 ***
    ## ICUTypeCardiac Surgery Recovery Unit   0.0000007935243281 ***
    ## ICUTypeMedical ICU                               0.004806 ** 
    ## ICUTypeSurgical ICU                              0.957929    
    ## Albumin_min                                      0.015952 *  
    ## Bilirubin_max                                    0.065522 .  
    ## BUN_max                                0.0000000000000297 ***
    ## HCO3_min                                         0.047442 *  
    ## Lactate_max                                      0.000570 ***
    ## Na_min                                           0.000542 ***
    ## pH_min                                           0.000990 ***
    ## RespRate_max                                     0.002545 ** 
    ## Urine_min                                        0.006177 ** 
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ##                                      exp(coef) exp(-coef) lower .95 upper .95
    ## Age                                     1.0343     0.9669    1.0289    1.0397
    ## ICUTypeCardiac Surgery Recovery Unit    0.4940     2.0243    0.3734    0.6536
    ## ICUTypeMedical ICU                      1.3689     0.7305    1.1005    1.7028
    ## ICUTypeSurgical ICU                     1.0067     0.9933    0.7843    1.2922
    ## Albumin_min                             0.8582     1.1653    0.7578    0.9718
    ## Bilirubin_max                           1.0147     0.9855    0.9991    1.0307
    ## BUN_max                                 1.0107     0.9894    1.0079    1.0135
    ## HCO3_min                                1.0175     0.9828    1.0002    1.0351
    ## Lactate_max                             1.0648     0.9391    1.0274    1.1036
    ## Na_min                                  0.9750     1.0256    0.9612    0.9891
    ## pH_min                                  0.5268     1.8983    0.3597    0.7714
    ## RespRate_max                            1.0144     0.9858    1.0050    1.0239
    ## Urine_min                               0.9974     1.0026    0.9956    0.9993
    ## 
    ## Concordance= 0.724  (se = 0.009 )
    ## Likelihood ratio test= 439.1  on 13 df,   p=<0.0000000000000002
    ## Wald test            = 422.9  on 13 df,   p=<0.0000000000000002
    ## Score (logrank) test = 457.6  on 13 df,   p=<0.0000000000000002
    # Calculate 2nd reduced model AIC
    AIC.mv_reduced2 <- calc_aic(ICU.mv_reduced2)
    AIC.mv_reduced2 #10171
    ## [1] 10171.34
    # 3rd reduced model by using step() function on the full model (which had the lowest AIC so far)
    ICU.mv_reduced3 <- step(ICU.mv_full, trace=1)
    ## Start:  AIC=10135.95
    ## Surv(Days, Status) ~ Age + Gender + ICUType + Weight_max + Albumin_min + 
    ##     Bilirubin_max + BUN_max + Creatinine_max + GCS_max + Glucose_min + 
    ##     Glucose_max + HCO3_min + HR_min + HR_max + K_min + K_max + 
    ##     Lactate_max + MAP_min + Na_min + Na_max + Platelets_min + 
    ##     PFratio + pH_min + pH_max + RespRate_min + RespRate_max + 
    ##     Temp_min + Temp_max + TroponinT_max + TroponinI_max + Urine_min + 
    ##     WBC_min + WBC_max
    ## 
    ##                  Df   AIC
    ## - PFratio         1 10134
    ## - Glucose_min     1 10134
    ## - Gender          1 10134
    ## - MAP_min         1 10134
    ## - Na_min          1 10134
    ## - Creatinine_max  1 10134
    ## - pH_max          1 10134
    ## - TroponinI_max   1 10134
    ## - K_max           1 10134
    ## - Platelets_min   1 10135
    ## - Glucose_max     1 10135
    ## - K_min           1 10135
    ## - TroponinT_max   1 10135
    ## - HR_max          1 10135
    ## - Temp_min        1 10135
    ## - RespRate_max    1 10135
    ## - Weight_max      1 10136
    ## - RespRate_min    1 10136
    ## <none>              10136
    ## - Na_max          1 10137
    ## - WBC_max         1 10137
    ## - Bilirubin_max   1 10137
    ## - WBC_min         1 10137
    ## - Albumin_min     1 10137
    ## - HCO3_min        1 10138
    ## - HR_min          1 10138
    ## - pH_min          1 10138
    ## - Lactate_max     1 10138
    ## - Urine_min       1 10139
    ## - Temp_max        1 10140
    ## - BUN_max         1 10163
    ## - GCS_max         1 10186
    ## - ICUType         3 10191
    ## - Age             1 10276
    ## 
    ## Step:  AIC=10133.95
    ## Surv(Days, Status) ~ Age + Gender + ICUType + Weight_max + Albumin_min + 
    ##     Bilirubin_max + BUN_max + Creatinine_max + GCS_max + Glucose_min + 
    ##     Glucose_max + HCO3_min + HR_min + HR_max + K_min + K_max + 
    ##     Lactate_max + MAP_min + Na_min + Na_max + Platelets_min + 
    ##     pH_min + pH_max + RespRate_min + RespRate_max + Temp_min + 
    ##     Temp_max + TroponinT_max + TroponinI_max + Urine_min + WBC_min + 
    ##     WBC_max
    ## 
    ##                  Df   AIC
    ## - Glucose_min     1 10132
    ## - Gender          1 10132
    ## - MAP_min         1 10132
    ## - Na_min          1 10132
    ## - Creatinine_max  1 10132
    ## - pH_max          1 10132
    ## - TroponinI_max   1 10132
    ## - K_max           1 10132
    ## - Platelets_min   1 10133
    ## - Glucose_max     1 10133
    ## - K_min           1 10133
    ## - TroponinT_max   1 10133
    ## - HR_max          1 10133
    ## - Temp_min        1 10133
    ## - RespRate_max    1 10133
    ## - Weight_max      1 10134
    ## - RespRate_min    1 10134
    ## <none>              10134
    ## - Na_max          1 10135
    ## - WBC_max         1 10135
    ## - Bilirubin_max   1 10135
    ## - WBC_min         1 10135
    ## - Albumin_min     1 10135
    ## - HCO3_min        1 10136
    ## - HR_min          1 10136
    ## - pH_min          1 10136
    ## - Lactate_max     1 10136
    ## - Urine_min       1 10137
    ## - Temp_max        1 10138
    ## - BUN_max         1 10162
    ## - GCS_max         1 10184
    ## - ICUType         3 10189
    ## - Age             1 10275
    ## 
    ## Step:  AIC=10132.02
    ## Surv(Days, Status) ~ Age + Gender + ICUType + Weight_max + Albumin_min + 
    ##     Bilirubin_max + BUN_max + Creatinine_max + GCS_max + Glucose_max + 
    ##     HCO3_min + HR_min + HR_max + K_min + K_max + Lactate_max + 
    ##     MAP_min + Na_min + Na_max + Platelets_min + pH_min + pH_max + 
    ##     RespRate_min + RespRate_max + Temp_min + Temp_max + TroponinT_max + 
    ##     TroponinI_max + Urine_min + WBC_min + WBC_max
    ## 
    ##                  Df   AIC
    ## - Gender          1 10130
    ## - MAP_min         1 10130
    ## - Na_min          1 10130
    ## - Creatinine_max  1 10130
    ## - pH_max          1 10130
    ## - TroponinI_max   1 10130
    ## - K_max           1 10130
    ## - Platelets_min   1 10131
    ## - Glucose_max     1 10131
    ## - K_min           1 10131
    ## - TroponinT_max   1 10131
    ## - HR_max          1 10131
    ## - Temp_min        1 10131
    ## - RespRate_max    1 10132
    ## - Weight_max      1 10132
    ## - RespRate_min    1 10132
    ## <none>              10132
    ## - Na_max          1 10133
    ## - WBC_max         1 10133
    ## - Bilirubin_max   1 10133
    ## - WBC_min         1 10133
    ## - Albumin_min     1 10133
    ## - HCO3_min        1 10134
    ## - HR_min          1 10134
    ## - pH_min          1 10134
    ## - Lactate_max     1 10134
    ## - Urine_min       1 10135
    ## - Temp_max        1 10136
    ## - BUN_max         1 10160
    ## - GCS_max         1 10182
    ## - ICUType         3 10187
    ## - Age             1 10273
    ## 
    ## Step:  AIC=10130.11
    ## Surv(Days, Status) ~ Age + ICUType + Weight_max + Albumin_min + 
    ##     Bilirubin_max + BUN_max + Creatinine_max + GCS_max + Glucose_max + 
    ##     HCO3_min + HR_min + HR_max + K_min + K_max + Lactate_max + 
    ##     MAP_min + Na_min + Na_max + Platelets_min + pH_min + pH_max + 
    ##     RespRate_min + RespRate_max + Temp_min + Temp_max + TroponinT_max + 
    ##     TroponinI_max + Urine_min + WBC_min + WBC_max
    ## 
    ##                  Df   AIC
    ## - MAP_min         1 10128
    ## - Na_min          1 10128
    ## - Creatinine_max  1 10128
    ## - pH_max          1 10128
    ## - K_max           1 10129
    ## - TroponinI_max   1 10129
    ## - Platelets_min   1 10129
    ## - K_min           1 10129
    ## - Glucose_max     1 10129
    ## - TroponinT_max   1 10129
    ## - HR_max          1 10129
    ## - Temp_min        1 10129
    ## - RespRate_max    1 10130
    ## - RespRate_min    1 10130
    ## <none>              10130
    ## - Weight_max      1 10130
    ## - WBC_max         1 10131
    ## - Na_max          1 10131
    ## - Bilirubin_max   1 10131
    ## - WBC_min         1 10131
    ## - Albumin_min     1 10132
    ## - HCO3_min        1 10132
    ## - HR_min          1 10132
    ## - pH_min          1 10132
    ## - Lactate_max     1 10133
    ## - Urine_min       1 10133
    ## - Temp_max        1 10134
    ## - BUN_max         1 10158
    ## - GCS_max         1 10180
    ## - ICUType         3 10185
    ## - Age             1 10271
    ## 
    ## Step:  AIC=10128.23
    ## Surv(Days, Status) ~ Age + ICUType + Weight_max + Albumin_min + 
    ##     Bilirubin_max + BUN_max + Creatinine_max + GCS_max + Glucose_max + 
    ##     HCO3_min + HR_min + HR_max + K_min + K_max + Lactate_max + 
    ##     Na_min + Na_max + Platelets_min + pH_min + pH_max + RespRate_min + 
    ##     RespRate_max + Temp_min + Temp_max + TroponinT_max + TroponinI_max + 
    ##     Urine_min + WBC_min + WBC_max
    ## 
    ##                  Df   AIC
    ## - Na_min          1 10126
    ## - Creatinine_max  1 10126
    ## - pH_max          1 10127
    ## - K_max           1 10127
    ## - TroponinI_max   1 10127
    ## - Platelets_min   1 10127
    ## - K_min           1 10127
    ## - Glucose_max     1 10127
    ## - TroponinT_max   1 10127
    ## - HR_max          1 10127
    ## - Temp_min        1 10127
    ## - RespRate_max    1 10128
    ## - RespRate_min    1 10128
    ## - Weight_max      1 10128
    ## <none>              10128
    ## - WBC_max         1 10129
    ## - Na_max          1 10129
    ## - Bilirubin_max   1 10129
    ## - WBC_min         1 10129
    ## - Albumin_min     1 10130
    ## - HCO3_min        1 10130
    ## - HR_min          1 10130
    ## - pH_min          1 10130
    ## - Lactate_max     1 10131
    ## - Urine_min       1 10131
    ## - Temp_max        1 10132
    ## - BUN_max         1 10156
    ## - GCS_max         1 10179
    ## - ICUType         3 10184
    ## - Age             1 10271
    ## 
    ## Step:  AIC=10126.46
    ## Surv(Days, Status) ~ Age + ICUType + Weight_max + Albumin_min + 
    ##     Bilirubin_max + BUN_max + Creatinine_max + GCS_max + Glucose_max + 
    ##     HCO3_min + HR_min + HR_max + K_min + K_max + Lactate_max + 
    ##     Na_max + Platelets_min + pH_min + pH_max + RespRate_min + 
    ##     RespRate_max + Temp_min + Temp_max + TroponinT_max + TroponinI_max + 
    ##     Urine_min + WBC_min + WBC_max
    ## 
    ##                  Df   AIC
    ## - K_max           1 10125
    ## - Creatinine_max  1 10125
    ## - pH_max          1 10125
    ## - K_min           1 10125
    ## - Platelets_min   1 10125
    ## - TroponinI_max   1 10125
    ## - TroponinT_max   1 10125
    ## - HR_max          1 10125
    ## - Glucose_max     1 10125
    ## - Temp_min        1 10126
    ## - RespRate_max    1 10126
    ## - RespRate_min    1 10126
    ## - Weight_max      1 10126
    ## <none>              10126
    ## - WBC_max         1 10127
    ## - WBC_min         1 10127
    ## - Bilirubin_max   1 10128
    ## - Albumin_min     1 10128
    ## - HCO3_min        1 10128
    ## - HR_min          1 10128
    ## - pH_min          1 10129
    ## - Lactate_max     1 10129
    ## - Urine_min       1 10130
    ## - Temp_max        1 10130
    ## - Na_max          1 10145
    ## - BUN_max         1 10154
    ## - GCS_max         1 10177
    ## - ICUType         3 10183
    ## - Age             1 10269
    ## 
    ## Step:  AIC=10124.71
    ## Surv(Days, Status) ~ Age + ICUType + Weight_max + Albumin_min + 
    ##     Bilirubin_max + BUN_max + Creatinine_max + GCS_max + Glucose_max + 
    ##     HCO3_min + HR_min + HR_max + K_min + Lactate_max + Na_max + 
    ##     Platelets_min + pH_min + pH_max + RespRate_min + RespRate_max + 
    ##     Temp_min + Temp_max + TroponinT_max + TroponinI_max + Urine_min + 
    ##     WBC_min + WBC_max
    ## 
    ##                  Df   AIC
    ## - K_min           1 10123
    ## - Creatinine_max  1 10123
    ## - pH_max          1 10123
    ## - Platelets_min   1 10123
    ## - TroponinI_max   1 10123
    ## - Glucose_max     1 10124
    ## - TroponinT_max   1 10124
    ## - HR_max          1 10124
    ## - Temp_min        1 10124
    ## - RespRate_max    1 10124
    ## - RespRate_min    1 10124
    ## - Weight_max      1 10125
    ## <none>              10125
    ## - WBC_max         1 10125
    ## - WBC_min         1 10126
    ## - Bilirubin_max   1 10126
    ## - Albumin_min     1 10126
    ## - HCO3_min        1 10126
    ## - HR_min          1 10127
    ## - pH_min          1 10127
    ## - Lactate_max     1 10127
    ## - Urine_min       1 10128
    ## - Temp_max        1 10129
    ## - Na_max          1 10143
    ## - BUN_max         1 10152
    ## - GCS_max         1 10175
    ## - ICUType         3 10182
    ## - Age             1 10268
    ## 
    ## Step:  AIC=10123
    ## Surv(Days, Status) ~ Age + ICUType + Weight_max + Albumin_min + 
    ##     Bilirubin_max + BUN_max + Creatinine_max + GCS_max + Glucose_max + 
    ##     HCO3_min + HR_min + HR_max + Lactate_max + Na_max + Platelets_min + 
    ##     pH_min + pH_max + RespRate_min + RespRate_max + Temp_min + 
    ##     Temp_max + TroponinT_max + TroponinI_max + Urine_min + WBC_min + 
    ##     WBC_max
    ## 
    ##                  Df   AIC
    ## - Creatinine_max  1 10121
    ## - pH_max          1 10121
    ## - Platelets_min   1 10121
    ## - TroponinI_max   1 10122
    ## - Glucose_max     1 10122
    ## - TroponinT_max   1 10122
    ## - HR_max          1 10122
    ## - Temp_min        1 10122
    ## - RespRate_max    1 10122
    ## - Weight_max      1 10123
    ## - RespRate_min    1 10123
    ## <none>              10123
    ## - WBC_max         1 10124
    ## - Bilirubin_max   1 10124
    ## - WBC_min         1 10124
    ## - Albumin_min     1 10124
    ## - HCO3_min        1 10125
    ## - HR_min          1 10125
    ## - pH_min          1 10125
    ## - Lactate_max     1 10125
    ## - Urine_min       1 10126
    ## - Temp_max        1 10127
    ## - Na_max          1 10143
    ## - BUN_max         1 10152
    ## - GCS_max         1 10174
    ## - ICUType         3 10184
    ## - Age             1 10268
    ## 
    ## Step:  AIC=10121.29
    ## Surv(Days, Status) ~ Age + ICUType + Weight_max + Albumin_min + 
    ##     Bilirubin_max + BUN_max + GCS_max + Glucose_max + HCO3_min + 
    ##     HR_min + HR_max + Lactate_max + Na_max + Platelets_min + 
    ##     pH_min + pH_max + RespRate_min + RespRate_max + Temp_min + 
    ##     Temp_max + TroponinT_max + TroponinI_max + Urine_min + WBC_min + 
    ##     WBC_max
    ## 
    ##                 Df   AIC
    ## - pH_max         1 10120
    ## - Platelets_min  1 10120
    ## - TroponinI_max  1 10120
    ## - Glucose_max    1 10120
    ## - TroponinT_max  1 10120
    ## - HR_max         1 10120
    ## - Temp_min       1 10120
    ## - RespRate_max   1 10120
    ## - RespRate_min   1 10121
    ## - Weight_max     1 10121
    ## <none>             10121
    ## - Bilirubin_max  1 10122
    ## - WBC_max        1 10122
    ## - Albumin_min    1 10123
    ## - WBC_min        1 10123
    ## - HCO3_min       1 10123
    ## - HR_min         1 10123
    ## - pH_min         1 10124
    ## - Lactate_max    1 10124
    ## - Urine_min      1 10124
    ## - Temp_max       1 10125
    ## - Na_max         1 10141
    ## - BUN_max        1 10165
    ## - GCS_max        1 10173
    ## - ICUType        3 10182
    ## - Age            1 10272
    ## 
    ## Step:  AIC=10119.7
    ## Surv(Days, Status) ~ Age + ICUType + Weight_max + Albumin_min + 
    ##     Bilirubin_max + BUN_max + GCS_max + Glucose_max + HCO3_min + 
    ##     HR_min + HR_max + Lactate_max + Na_max + Platelets_min + 
    ##     pH_min + RespRate_min + RespRate_max + Temp_min + Temp_max + 
    ##     TroponinT_max + TroponinI_max + Urine_min + WBC_min + WBC_max
    ## 
    ##                 Df   AIC
    ## - TroponinI_max  1 10118
    ## - Platelets_min  1 10118
    ## - Glucose_max    1 10118
    ## - TroponinT_max  1 10119
    ## - HR_max         1 10119
    ## - Temp_min       1 10119
    ## - RespRate_max   1 10119
    ## <none>             10120
    ## - RespRate_min   1 10120
    ## - Weight_max     1 10120
    ## - Bilirubin_max  1 10121
    ## - WBC_max        1 10121
    ## - Albumin_min    1 10121
    ## - WBC_min        1 10121
    ## - HR_min         1 10122
    ## - pH_min         1 10122
    ## - Lactate_max    1 10122
    ## - HCO3_min       1 10122
    ## - Urine_min      1 10122
    ## - Temp_max       1 10123
    ## - Na_max         1 10140
    ## - BUN_max        1 10163
    ## - GCS_max        1 10174
    ## - ICUType        3 10182
    ## - Age            1 10270
    ## 
    ## Step:  AIC=10118.15
    ## Surv(Days, Status) ~ Age + ICUType + Weight_max + Albumin_min + 
    ##     Bilirubin_max + BUN_max + GCS_max + Glucose_max + HCO3_min + 
    ##     HR_min + HR_max + Lactate_max + Na_max + Platelets_min + 
    ##     pH_min + RespRate_min + RespRate_max + Temp_min + Temp_max + 
    ##     TroponinT_max + Urine_min + WBC_min + WBC_max
    ## 
    ##                 Df   AIC
    ## - Platelets_min  1 10117
    ## - Glucose_max    1 10117
    ## - TroponinT_max  1 10117
    ## - Temp_min       1 10117
    ## - HR_max         1 10118
    ## <none>             10118
    ## - RespRate_min   1 10118
    ## - Weight_max     1 10118
    ## - RespRate_max   1 10118
    ## - Bilirubin_max  1 10119
    ## - WBC_max        1 10119
    ## - WBC_min        1 10119
    ## - Albumin_min    1 10120
    ## - HR_min         1 10120
    ## - pH_min         1 10120
    ## - Lactate_max    1 10120
    ## - Urine_min      1 10121
    ## - HCO3_min       1 10121
    ## - Temp_max       1 10122
    ## - Na_max         1 10138
    ## - BUN_max        1 10166
    ## - GCS_max        1 10172
    ## - ICUType        3 10181
    ## - Age            1 10268
    ## 
    ## Step:  AIC=10116.63
    ## Surv(Days, Status) ~ Age + ICUType + Weight_max + Albumin_min + 
    ##     Bilirubin_max + BUN_max + GCS_max + Glucose_max + HCO3_min + 
    ##     HR_min + HR_max + Lactate_max + Na_max + pH_min + RespRate_min + 
    ##     RespRate_max + Temp_min + Temp_max + TroponinT_max + Urine_min + 
    ##     WBC_min + WBC_max
    ## 
    ##                 Df   AIC
    ## - Glucose_max    1 10116
    ## - TroponinT_max  1 10116
    ## - Temp_min       1 10116
    ## - HR_max         1 10116
    ## <none>             10117
    ## - Weight_max     1 10117
    ## - RespRate_min   1 10117
    ## - RespRate_max   1 10117
    ## - WBC_min        1 10118
    ## - WBC_max        1 10118
    ## - Bilirubin_max  1 10118
    ## - HR_min         1 10118
    ## - Albumin_min    1 10118
    ## - pH_min         1 10119
    ## - Lactate_max    1 10119
    ## - Urine_min      1 10119
    ## - HCO3_min       1 10120
    ## - Temp_max       1 10120
    ## - Na_max         1 10136
    ## - BUN_max        1 10165
    ## - GCS_max        1 10171
    ## - ICUType        3 10180
    ## - Age            1 10268
    ## 
    ## Step:  AIC=10115.63
    ## Surv(Days, Status) ~ Age + ICUType + Weight_max + Albumin_min + 
    ##     Bilirubin_max + BUN_max + GCS_max + HCO3_min + HR_min + HR_max + 
    ##     Lactate_max + Na_max + pH_min + RespRate_min + RespRate_max + 
    ##     Temp_min + Temp_max + TroponinT_max + Urine_min + WBC_min + 
    ##     WBC_max
    ## 
    ##                 Df   AIC
    ## - TroponinT_max  1 10115
    ## - Temp_min       1 10115
    ## - HR_max         1 10115
    ## - Weight_max     1 10116
    ## <none>             10116
    ## - RespRate_max   1 10116
    ## - RespRate_min   1 10116
    ## - WBC_min        1 10116
    ## - WBC_max        1 10116
    ## - Bilirubin_max  1 10117
    ## - Albumin_min    1 10117
    ## - HR_min         1 10117
    ## - pH_min         1 10117
    ## - HCO3_min       1 10118
    ## - Urine_min      1 10118
    ## - Temp_max       1 10119
    ## - Lactate_max    1 10119
    ## - Na_max         1 10135
    ## - BUN_max        1 10164
    ## - GCS_max        1 10171
    ## - ICUType        3 10182
    ## - Age            1 10268
    ## 
    ## Step:  AIC=10114.75
    ## Surv(Days, Status) ~ Age + ICUType + Weight_max + Albumin_min + 
    ##     Bilirubin_max + BUN_max + GCS_max + HCO3_min + HR_min + HR_max + 
    ##     Lactate_max + Na_max + pH_min + RespRate_min + RespRate_max + 
    ##     Temp_min + Temp_max + Urine_min + WBC_min + WBC_max
    ## 
    ##                 Df   AIC
    ## - Temp_min       1 10114
    ## - HR_max         1 10114
    ## - Weight_max     1 10115
    ## <none>             10115
    ## - RespRate_min   1 10115
    ## - RespRate_max   1 10115
    ## - WBC_max        1 10116
    ## - WBC_min        1 10116
    ## - Albumin_min    1 10116
    ## - HR_min         1 10116
    ## - Bilirubin_max  1 10116
    ## - HCO3_min       1 10117
    ## - pH_min         1 10118
    ## - Urine_min      1 10118
    ## - Temp_max       1 10118
    ## - Lactate_max    1 10120
    ## - Na_max         1 10134
    ## - BUN_max        1 10163
    ## - GCS_max        1 10170
    ## - ICUType        3 10182
    ## - Age            1 10266
    ## 
    ## Step:  AIC=10113.91
    ## Surv(Days, Status) ~ Age + ICUType + Weight_max + Albumin_min + 
    ##     Bilirubin_max + BUN_max + GCS_max + HCO3_min + HR_min + HR_max + 
    ##     Lactate_max + Na_max + pH_min + RespRate_min + RespRate_max + 
    ##     Temp_max + Urine_min + WBC_min + WBC_max
    ## 
    ##                 Df   AIC
    ## - HR_max         1 10113
    ## <none>             10114
    ## - Weight_max     1 10114
    ## - RespRate_max   1 10114
    ## - RespRate_min   1 10114
    ## - WBC_min        1 10115
    ## - WBC_max        1 10115
    ## - HR_min         1 10115
    ## - Bilirubin_max  1 10115
    ## - Albumin_min    1 10115
    ## - HCO3_min       1 10116
    ## - pH_min         1 10117
    ## - Urine_min      1 10117
    ## - Lactate_max    1 10120
    ## - Temp_max       1 10120
    ## - Na_max         1 10133
    ## - BUN_max        1 10162
    ## - GCS_max        1 10170
    ## - ICUType        3 10180
    ## - Age            1 10265
    ## 
    ## Step:  AIC=10113.1
    ## Surv(Days, Status) ~ Age + ICUType + Weight_max + Albumin_min + 
    ##     Bilirubin_max + BUN_max + GCS_max + HCO3_min + HR_min + Lactate_max + 
    ##     Na_max + pH_min + RespRate_min + RespRate_max + Temp_max + 
    ##     Urine_min + WBC_min + WBC_max
    ## 
    ##                 Df   AIC
    ## <none>             10113
    ## - RespRate_min   1 10113
    ## - RespRate_max   1 10114
    ## - WBC_max        1 10114
    ## - Weight_max     1 10114
    ## - WBC_min        1 10114
    ## - Bilirubin_max  1 10114
    ## - Albumin_min    1 10115
    ## - HCO3_min       1 10115
    ## - pH_min         1 10116
    ## - Urine_min      1 10117
    ## - HR_min         1 10117
    ## - Temp_max       1 10119
    ## - Lactate_max    1 10120
    ## - Na_max         1 10132
    ## - BUN_max        1 10160
    ## - GCS_max        1 10169
    ## - ICUType        3 10182
    ## - Age            1 10265
    summary(ICU.mv_reduced3)
    ## Call:
    ## coxph(formula = Surv(Days, Status) ~ Age + ICUType + Weight_max + 
    ##     Albumin_min + Bilirubin_max + BUN_max + GCS_max + HCO3_min + 
    ##     HR_min + Lactate_max + Na_max + pH_min + RespRate_min + RespRate_max + 
    ##     Temp_max + Urine_min + WBC_min + WBC_max, data = nm_icu_model_df1)
    ## 
    ##   n= 1915, number of events= 721 
    ## 
    ##                                            coef  exp(coef)   se(coef)      z
    ## Age                                   0.0337030  1.0342774  0.0028800 11.703
    ## ICUTypeCardiac Surgery Recovery Unit -0.7585749  0.4683334  0.1455045 -5.213
    ## ICUTypeMedical ICU                    0.2665894  1.3055043  0.1118935  2.383
    ## ICUTypeSurgical ICU                  -0.0597760  0.9419755  0.1289216 -0.464
    ## Weight_max                           -0.0028717  0.9971324  0.0018165 -1.581
    ## Albumin_min                          -0.1217041  0.8854103  0.0647304 -1.880
    ## Bilirubin_max                         0.0151357  1.0152509  0.0078127  1.937
    ## BUN_max                               0.0108042  1.0108628  0.0014283  7.564
    ## GCS_max                              -0.1088301  0.8968828  0.0138841 -7.838
    ## HCO3_min                              0.0174338  1.0175867  0.0089639  1.945
    ## HR_min                                0.0064653  1.0064862  0.0026116  2.476
    ## Lactate_max                           0.0570025  1.0586585  0.0186807  3.051
    ## Na_max                               -0.0358594  0.9647759  0.0079585 -4.506
    ## pH_min                               -0.5088123  0.6012092  0.1823407 -2.790
    ## RespRate_min                         -0.0196914  0.9805013  0.0128529 -1.532
    ## RespRate_max                          0.0091086  1.0091502  0.0056285  1.618
    ## Temp_max                             -0.1436890  0.8661571  0.0527479 -2.724
    ## Urine_min                            -0.0020642  0.9979380  0.0009474 -2.179
    ## WBC_min                               0.0221331  1.0223798  0.0136925  1.616
    ## WBC_max                              -0.0178972  0.9822620  0.0114290 -1.566
    ##                                                  Pr(>|z|)    
    ## Age                                  < 0.0000000000000002 ***
    ## ICUTypeCardiac Surgery Recovery Unit  0.00000018539857563 ***
    ## ICUTypeMedical ICU                                0.01719 *  
    ## ICUTypeSurgical ICU                               0.64289    
    ## Weight_max                                        0.11391    
    ## Albumin_min                                       0.06008 .  
    ## Bilirubin_max                                     0.05271 .  
    ## BUN_max                               0.00000000000003898 ***
    ## GCS_max                               0.00000000000000456 ***
    ## HCO3_min                                          0.05179 .  
    ## HR_min                                            0.01330 *  
    ## Lactate_max                                       0.00228 ** 
    ## Na_max                                0.00000661319368369 ***
    ## pH_min                                            0.00526 ** 
    ## RespRate_min                                      0.12551    
    ## RespRate_max                                      0.10560    
    ## Temp_max                                          0.00645 ** 
    ## Urine_min                                         0.02934 *  
    ## WBC_min                                           0.10600    
    ## WBC_max                                           0.11736    
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ##                                      exp(coef) exp(-coef) lower .95 upper .95
    ## Age                                     1.0343     0.9669    1.0285    1.0401
    ## ICUTypeCardiac Surgery Recovery Unit    0.4683     2.1352    0.3521    0.6229
    ## ICUTypeMedical ICU                      1.3055     0.7660    1.0484    1.6256
    ## ICUTypeSurgical ICU                     0.9420     1.0616    0.7316    1.2128
    ## Weight_max                              0.9971     1.0029    0.9936    1.0007
    ## Albumin_min                             0.8854     1.1294    0.7799    1.0052
    ## Bilirubin_max                           1.0153     0.9850    0.9998    1.0309
    ## BUN_max                                 1.0109     0.9893    1.0080    1.0137
    ## GCS_max                                 0.8969     1.1150    0.8728    0.9216
    ## HCO3_min                                1.0176     0.9827    0.9999    1.0356
    ## HR_min                                  1.0065     0.9936    1.0013    1.0117
    ## Lactate_max                             1.0587     0.9446    1.0206    1.0981
    ## Na_max                                  0.9648     1.0365    0.9498    0.9799
    ## pH_min                                  0.6012     1.6633    0.4205    0.8595
    ## RespRate_min                            0.9805     1.0199    0.9561    1.0055
    ## RespRate_max                            1.0092     0.9909    0.9981    1.0203
    ## Temp_max                                0.8662     1.1545    0.7811    0.9605
    ## Urine_min                               0.9979     1.0021    0.9961    0.9998
    ## WBC_min                                 1.0224     0.9781    0.9953    1.0502
    ## WBC_max                                 0.9823     1.0181    0.9605    1.0045
    ## 
    ## Concordance= 0.741  (se = 0.009 )
    ## Likelihood ratio test= 511.4  on 20 df,   p=<0.0000000000000002
    ## Wald test            = 497.9  on 20 df,   p=<0.0000000000000002
    ## Score (logrank) test = 541.4  on 20 df,   p=<0.0000000000000002
    ## Interestingly: GCS_max, HR_min & Na_max have worked their way back in (not significant on log-rank)
    
    # Calculate 3rd reduced model AIC
    AIC.mv_reduced3 <- calc_aic(ICU.mv_reduced3)
    AIC.mv_reduced3 #10113
    ## [1] 10113.1
    # 4th reduced model using significant variables (using cut off p < 0.1) from ICU.mv_reduced3 
    ICU.mv_reduced4 <- coxph(Surv(Days, Status) ~
                            Age + ICUType + Albumin_min + Bilirubin_max + BUN_max + 
                            GCS_max + HCO3_min + HR_min + Lactate_max + Na_max + 
                            pH_min + Temp_max + Urine_min,
                            data = nm_icu_model_df1)
    summary(ICU.mv_reduced4)
    ## Call:
    ## coxph(formula = Surv(Days, Status) ~ Age + ICUType + Albumin_min + 
    ##     Bilirubin_max + BUN_max + GCS_max + HCO3_min + HR_min + Lactate_max + 
    ##     Na_max + pH_min + Temp_max + Urine_min, data = nm_icu_model_df1)
    ## 
    ##   n= 1915, number of events= 721 
    ## 
    ##                                            coef  exp(coef)   se(coef)      z
    ## Age                                   0.0350388  1.0356599  0.0027689 12.654
    ## ICUTypeCardiac Surgery Recovery Unit -0.7506795  0.4720457  0.1436016 -5.228
    ## ICUTypeMedical ICU                    0.2966536  1.3453492  0.1113497  2.664
    ## ICUTypeSurgical ICU                  -0.0489970  0.9521840  0.1281524 -0.382
    ## Albumin_min                          -0.0975028  0.9070998  0.0640981 -1.521
    ## Bilirubin_max                         0.0176857  1.0178431  0.0075944  2.329
    ## BUN_max                               0.0103542  1.0104080  0.0013927  7.435
    ## GCS_max                              -0.1025152  0.9025644  0.0122724 -8.353
    ## HCO3_min                              0.0169520  1.0170965  0.0086722  1.955
    ## HR_min                                0.0064894  1.0065105  0.0025183  2.577
    ## Lactate_max                           0.0560927  1.0576957  0.0185001  3.032
    ## Na_max                               -0.0362758  0.9643743  0.0078693 -4.610
    ## pH_min                               -0.4684910  0.6259461  0.1892577 -2.475
    ## Temp_max                             -0.1537885  0.8574533  0.0518889 -2.964
    ## Urine_min                            -0.0019496  0.9980523  0.0009352 -2.085
    ##                                                  Pr(>|z|)    
    ## Age                                  < 0.0000000000000002 ***
    ## ICUTypeCardiac Surgery Recovery Unit    0.000000171804359 ***
    ## ICUTypeMedical ICU                                0.00772 ** 
    ## ICUTypeSurgical ICU                               0.70221    
    ## Albumin_min                                       0.12822    
    ## Bilirubin_max                                     0.01987 *  
    ## BUN_max                                 0.000000000000105 ***
    ## GCS_max                              < 0.0000000000000002 ***
    ## HCO3_min                                          0.05061 .  
    ## HR_min                                            0.00997 ** 
    ## Lactate_max                                       0.00243 ** 
    ## Na_max                                  0.000004031402074 ***
    ## pH_min                                            0.01331 *  
    ## Temp_max                                          0.00304 ** 
    ## Urine_min                                         0.03710 *  
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ##                                      exp(coef) exp(-coef) lower .95 upper .95
    ## Age                                     1.0357     0.9656    1.0301    1.0413
    ## ICUTypeCardiac Surgery Recovery Unit    0.4720     2.1184    0.3562    0.6255
    ## ICUTypeMedical ICU                      1.3453     0.7433    1.0816    1.6735
    ## ICUTypeSurgical ICU                     0.9522     1.0502    0.7407    1.2241
    ## Albumin_min                             0.9071     1.1024    0.8000    1.0285
    ## Bilirubin_max                           1.0178     0.9825    1.0028    1.0331
    ## BUN_max                                 1.0104     0.9897    1.0077    1.0132
    ## GCS_max                                 0.9026     1.1080    0.8811    0.9245
    ## HCO3_min                                1.0171     0.9832    1.0000    1.0345
    ## HR_min                                  1.0065     0.9935    1.0016    1.0115
    ## Lactate_max                             1.0577     0.9455    1.0200    1.0968
    ## Na_max                                  0.9644     1.0369    0.9496    0.9794
    ## pH_min                                  0.6259     1.5976    0.4320    0.9071
    ## Temp_max                                0.8575     1.1662    0.7745    0.9492
    ## Urine_min                               0.9981     1.0020    0.9962    0.9999
    ## 
    ## Concordance= 0.738  (se = 0.009 )
    ## Likelihood ratio test= 501.6  on 15 df,   p=<0.0000000000000002
    ## Wald test            = 481.3  on 15 df,   p=<0.0000000000000002
    ## Score (logrank) test = 519.6  on 15 df,   p=<0.0000000000000002
    # Calculate 4th reduced model AIC
    AIC.mv_reduced4 <- calc_aic(ICU.mv_reduced4)
    AIC.mv_reduced4 #10112
    ## [1] 10112.83
    # Comparing models with LRT
    lapply(list(ICU.mv_reduced1, ICU.mv_reduced2, ICU.mv_reduced3, ICU.mv_reduced4), 
           function(reduced) {print(anova(ICU.mv_full, reduced))} )
    ## Analysis of Deviance Table
    ##  Cox model: response is  Surv(Days, Status)
    ##  Model 1: ~ Age + Gender + ICUType + Weight_max + Albumin_min + Bilirubin_max + BUN_max + Creatinine_max + GCS_max + Glucose_min + Glucose_max + HCO3_min + HR_min + HR_max + K_min + K_max + Lactate_max + MAP_min + Na_min + Na_max + Platelets_min + PFratio + pH_min + pH_max + RespRate_min + RespRate_max + Temp_min + Temp_max + TroponinT_max + TroponinI_max + Urine_min + WBC_min + WBC_max
    ##  Model 2: ~ Age + ICUType + Weight_max + Albumin_min + Bilirubin_max + BUN_max + Creatinine_max + Glucose_max + HCO3_min + K_max + Lactate_max + MAP_min + Na_min + pH_min + pH_max + RespRate_min + RespRate_max + Temp_min + Temp_max + TroponinT_max + Urine_min
    ##    loglik Chisq Df     P(>|Chi|)    
    ## 1 -5033.0                           
    ## 2 -5066.2 66.37 12 0.00000000152 ***
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## Analysis of Deviance Table
    ##  Cox model: response is  Surv(Days, Status)
    ##  Model 1: ~ Age + Gender + ICUType + Weight_max + Albumin_min + Bilirubin_max + BUN_max + Creatinine_max + GCS_max + Glucose_min + Glucose_max + HCO3_min + HR_min + HR_max + K_min + K_max + Lactate_max + MAP_min + Na_min + Na_max + Platelets_min + PFratio + pH_min + pH_max + RespRate_min + RespRate_max + Temp_min + Temp_max + TroponinT_max + TroponinI_max + Urine_min + WBC_min + WBC_max
    ##  Model 2: ~ Age + ICUType + Albumin_min + Bilirubin_max + BUN_max + HCO3_min + Lactate_max + Na_min + pH_min + RespRate_max + Urine_min
    ##    loglik  Chisq Df     P(>|Chi|)    
    ## 1 -5033.0                            
    ## 2 -5072.7 79.388 22 0.00000002043 ***
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## Analysis of Deviance Table
    ##  Cox model: response is  Surv(Days, Status)
    ##  Model 1: ~ Age + Gender + ICUType + Weight_max + Albumin_min + Bilirubin_max + BUN_max + Creatinine_max + GCS_max + Glucose_min + Glucose_max + HCO3_min + HR_min + HR_max + K_min + K_max + Lactate_max + MAP_min + Na_min + Na_max + Platelets_min + PFratio + pH_min + pH_max + RespRate_min + RespRate_max + Temp_min + Temp_max + TroponinT_max + TroponinI_max + Urine_min + WBC_min + WBC_max
    ##  Model 2: ~ Age + ICUType + Weight_max + Albumin_min + Bilirubin_max + BUN_max + GCS_max + HCO3_min + HR_min + Lactate_max + Na_max + pH_min + RespRate_min + RespRate_max + Temp_max + Urine_min + WBC_min + WBC_max
    ##    loglik  Chisq Df P(>|Chi|)
    ## 1 -5033.0                    
    ## 2 -5036.5 7.1483 15    0.9534
    ## Analysis of Deviance Table
    ##  Cox model: response is  Surv(Days, Status)
    ##  Model 1: ~ Age + Gender + ICUType + Weight_max + Albumin_min + Bilirubin_max + BUN_max + Creatinine_max + GCS_max + Glucose_min + Glucose_max + HCO3_min + HR_min + HR_max + K_min + K_max + Lactate_max + MAP_min + Na_min + Na_max + Platelets_min + PFratio + pH_min + pH_max + RespRate_min + RespRate_max + Temp_min + Temp_max + TroponinT_max + TroponinI_max + Urine_min + WBC_min + WBC_max
    ##  Model 2: ~ Age + ICUType + Albumin_min + Bilirubin_max + BUN_max + GCS_max + HCO3_min + HR_min + Lactate_max + Na_max + pH_min + Temp_max + Urine_min
    ##    loglik  Chisq Df P(>|Chi|)
    ## 1 -5033.0                    
    ## 2 -5041.4 16.877 20    0.6609
    ## [[1]]
    ## Analysis of Deviance Table
    ##  Cox model: response is  Surv(Days, Status)
    ##  Model 1: ~ Age + Gender + ICUType + Weight_max + Albumin_min + Bilirubin_max + BUN_max + Creatinine_max + GCS_max + Glucose_min + Glucose_max + HCO3_min + HR_min + HR_max + K_min + K_max + Lactate_max + MAP_min + Na_min + Na_max + Platelets_min + PFratio + pH_min + pH_max + RespRate_min + RespRate_max + Temp_min + Temp_max + TroponinT_max + TroponinI_max + Urine_min + WBC_min + WBC_max
    ##  Model 2: ~ Age + ICUType + Weight_max + Albumin_min + Bilirubin_max + BUN_max + Creatinine_max + Glucose_max + HCO3_min + K_max + Lactate_max + MAP_min + Na_min + pH_min + pH_max + RespRate_min + RespRate_max + Temp_min + Temp_max + TroponinT_max + Urine_min
    ##    loglik Chisq Df     P(>|Chi|)    
    ## 1 -5033.0                           
    ## 2 -5066.2 66.37 12 0.00000000152 ***
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## [[2]]
    ## Analysis of Deviance Table
    ##  Cox model: response is  Surv(Days, Status)
    ##  Model 1: ~ Age + Gender + ICUType + Weight_max + Albumin_min + Bilirubin_max + BUN_max + Creatinine_max + GCS_max + Glucose_min + Glucose_max + HCO3_min + HR_min + HR_max + K_min + K_max + Lactate_max + MAP_min + Na_min + Na_max + Platelets_min + PFratio + pH_min + pH_max + RespRate_min + RespRate_max + Temp_min + Temp_max + TroponinT_max + TroponinI_max + Urine_min + WBC_min + WBC_max
    ##  Model 2: ~ Age + ICUType + Albumin_min + Bilirubin_max + BUN_max + HCO3_min + Lactate_max + Na_min + pH_min + RespRate_max + Urine_min
    ##    loglik  Chisq Df     P(>|Chi|)    
    ## 1 -5033.0                            
    ## 2 -5072.7 79.388 22 0.00000002043 ***
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## [[3]]
    ## Analysis of Deviance Table
    ##  Cox model: response is  Surv(Days, Status)
    ##  Model 1: ~ Age + Gender + ICUType + Weight_max + Albumin_min + Bilirubin_max + BUN_max + Creatinine_max + GCS_max + Glucose_min + Glucose_max + HCO3_min + HR_min + HR_max + K_min + K_max + Lactate_max + MAP_min + Na_min + Na_max + Platelets_min + PFratio + pH_min + pH_max + RespRate_min + RespRate_max + Temp_min + Temp_max + TroponinT_max + TroponinI_max + Urine_min + WBC_min + WBC_max
    ##  Model 2: ~ Age + ICUType + Weight_max + Albumin_min + Bilirubin_max + BUN_max + GCS_max + HCO3_min + HR_min + Lactate_max + Na_max + pH_min + RespRate_min + RespRate_max + Temp_max + Urine_min + WBC_min + WBC_max
    ##    loglik  Chisq Df P(>|Chi|)
    ## 1 -5033.0                    
    ## 2 -5036.5 7.1483 15    0.9534
    ## 
    ## [[4]]
    ## Analysis of Deviance Table
    ##  Cox model: response is  Surv(Days, Status)
    ##  Model 1: ~ Age + Gender + ICUType + Weight_max + Albumin_min + Bilirubin_max + BUN_max + Creatinine_max + GCS_max + Glucose_min + Glucose_max + HCO3_min + HR_min + HR_max + K_min + K_max + Lactate_max + MAP_min + Na_min + Na_max + Platelets_min + PFratio + pH_min + pH_max + RespRate_min + RespRate_max + Temp_min + Temp_max + TroponinT_max + TroponinI_max + Urine_min + WBC_min + WBC_max
    ##  Model 2: ~ Age + ICUType + Albumin_min + Bilirubin_max + BUN_max + GCS_max + HCO3_min + HR_min + Lactate_max + Na_max + pH_min + Temp_max + Urine_min
    ##    loglik  Chisq Df P(>|Chi|)
    ## 1 -5033.0                    
    ## 2 -5041.4 16.877 20    0.6609
    ## Results: reduced1 and reduced2 - reject the null hypothesis that the reduced models are better (they are worse)
    ##          reduced3 and reduced4 - DONT reject the null hypothesis 
    ##                                    --> therefore the reduced models are better than the full model (matches our AICs)
    
    
    # Print the AICs all together to review
    aic_output <- c(AIC.mv_full, AIC.mv_reduced1, AIC.mv_reduced2, AIC.mv_reduced3, AIC.mv_reduced4)
    names(aic_output) <- c('Full AIC', 'Reduced 1 AIC', 'Reduced 2 AIC', 'Reduced 3 AIC', 'Reduced 4 AIC')
    print(aic_output)
    ##      Full AIC Reduced 1 AIC Reduced 2 AIC Reduced 3 AIC Reduced 4 AIC 
    ##      10135.95      10178.32      10171.34      10113.10      10112.83
    ## Decision: use ICU.mv_reduced4 as the provisional final model (lowest AIC and non-significant LRT)
    ## Note: the model 3 still has the better likelihood statistic than Model 4, but we choose model 4 for parsimony

    Selecting a multivariable Cox proportional hazards model:

    1. Full model - a model with all selected variables (excluding those with high degree of missingness) has been fitted. In the resulting fitted model, Age, ICU type, BUN_max, GCS_max, are highly significant. Lactate_max, pH_min, Temp_max and urine_min are also significant at 5% significance level. Furthermore, Albumin_min, Bilirubin_max, HCO3_min, HR_min, WBC_min and WBC_max are significant at 10% significance level. The resulting model has a maximised likelihood of 518.5. The log rank test statistic is highly significant (p-value close to 0), indicating that the variables in the full model have significant explanatory power on ICU population survival. Note, the AIC of the full model is 10,136.

    2. Reduced Model 1 - for parsimony, we look for a reduced model with fewer variables than can adequately explain survival rates for the ICU population. Our first attempt is to only include variables that resulted in a significant log rank test for the respective univariate models. Since the reduced model is nested in the full model, we use a likelihood ratio test to compare the two model. We reject the null hypothesis (p-value is 0.000000000152) and conclude that the full model is a better fit to the data. This conclusion is echoed when comparing the models’ AICs - the reduced model has a higher AIC of 10,178.

    3. Reduced Model 2 - the second attempt, reduces the Reduced Model 1 by only including variables that were significant at a 10% significance level. We can again use a likelihood ratio test to compare this model with the full model as the models are nested. We reject the null hypothesis (p-value is 0.00000002043) and conclude that the full model is a better fit to the data. Whilst the AIC for Model 2 (10,171) is lower than for Model 1, it is higher than the Full Model, which leads to the same conclusion as the LRT test.

    4. Reduced Model 3 - the third attempt starts with the full model and uses the step function to search the model space for a model with a better fit and fewer covariates. After 17 iterations, the reduced model includes 18 covariates. Interestingly, GCS_max, HR_min & Na_max are now being included in the model despite the non-significant log rank tests for the univariate models. When compared with the full model, the null hypothesis of the LRT test (p-value = 0.95)is accepted and we can conclude that the reduced model is a better fit to the data than the full model. Furthermore, the AIC is reduced to 10,113.

    5. Reduced Model 4 - in this model, we take Model 3 and only include the significant variables at 10% significance level (i.e. removed Weight_max, RespRate_min, respRate_max, WBC_min, WBC_max). When compared with the full model, the null hypothesis of the LRT test (p-value = 0.66) is accepted and we can conclude that the reduced model is a better fit to the data than the full model. Furthermore, the AIC is reduced to 10,112 which is slightly lower than the AIC for Reduced Model 3.

    Cox proportional hazards model assumption checking:

    ## Testing assumptions ##
    
    # Testing for proportional hazards assumption of ICU.mv_reduced4 using cox.zph()
    cox.zph(ICU.mv_reduced4, terms=FALSE)
    ##                                         chisq df              p
    ## Age                                   1.04471  1        0.30673
    ## ICUTypeCardiac Surgery Recovery Unit 10.34626  1        0.00130
    ## ICUTypeMedical ICU                    0.00654  1        0.93553
    ## ICUTypeSurgical ICU                   4.60886  1        0.03181
    ## Albumin_min                          12.67940  1        0.00037
    ## Bilirubin_max                        11.96366  1        0.00054
    ## BUN_max                               0.93552  1        0.33343
    ## GCS_max                              25.48016  1 0.000000446955
    ## HCO3_min                             25.17651  1 0.000000523154
    ## HR_min                                4.47650  1        0.03436
    ## Lactate_max                          32.07772  1 0.000000014813
    ## Na_max                                0.05096  1        0.82140
    ## pH_min                                0.41234  1        0.52078
    ## Temp_max                              1.89556  1        0.16858
    ## Urine_min                             3.24395  1        0.07169
    ## GLOBAL                               89.96094 15 0.000000000001
    ## Result: statistically significant global test, therefore the proportional hazards model is violated
    ##         (the variables that violate are: ICUType, Albumin_min, Bilirubin_max, GCS_max, HCO3_min, HR_min, Lactate_max)
    
    
    # Including time x covariate interactions to fix proportional hazards for problematic variables
    
    # Split the dataset at 90 days (~ 3 months)
    # Suspect there may be some systematic differences in patients who survive less than or greater than 3 months after ICU admission
    ICU.split <- survSplit(Surv(Days, Status) ~ ., data = nm_icu_model_df1, cut=c(90), episode= "tgroup", id="id2")
    head(ICU.split)
    ##   RecordID in_hospital_death Age Gender                       ICUType
    ## 1   132540                 0  76   Male Cardiac Surgery Recovery Unit
    ## 2   132540                 0  76   Male Cardiac Surgery Recovery Unit
    ## 3   132541                 0  44 Female                   Medical ICU
    ## 4   132541                 0  44 Female                   Medical ICU
    ## 5   132543                 0  68   Male                   Medical ICU
    ## 6   132543                 0  68   Male                   Medical ICU
    ##   Weight_max Albumin_min Bilirubin_max BUN_max Creatinine_max GCS_max
    ## 1       80.6         2.2           1.2      18            1.2      15
    ## 2       80.6         2.2           1.2      18            1.2      15
    ## 3       56.7         2.3           3.0       8            0.4       8
    ## 4       56.7         2.3           3.0       8            0.4       8
    ## 5       84.6         4.4           0.2      23            0.9      15
    ## 6       84.6         4.4           0.2      23            0.9      15
    ##   Glucose_min Glucose_max HCO3_min HR_min HR_max K_min K_max Lactate_max
    ## 1         105         105       21     80     88   4.3   4.3         2.9
    ## 2         105         105       21     80     88   4.3   4.3         2.9
    ## 3         119         141       24     57    113   3.3   8.6         1.9
    ## 4         119         141       24     57    113   3.3   8.6         1.9
    ## 5         106         129       27     57     88   4.0   4.2         1.2
    ## 6         106         129       27     57     88   4.0   4.2         1.2
    ##   MAP_min Na_min Na_max Platelets_min PFratio pH_min pH_max RespRate_min
    ## 1      43    139    139           164      89   7.34   7.45           11
    ## 2      43    139    139           164      89   7.34   7.45           11
    ## 3      71    137    140            72      65   7.51   7.51           18
    ## 4      71    137    140            72      65   7.51   7.51           18
    ## 5      72    140    141           315      64   7.47   7.51           12
    ## 6      72    140    141           315      64   7.47   7.51           12
    ##   RespRate_max Temp_min Temp_max TroponinT_max TroponinI_max Urine_min WBC_min
    ## 1           36     34.5     37.9          0.43          31.7         0     7.4
    ## 2           36     34.5     37.9          0.43          31.7         0     7.4
    ## 3           33     36.7     39.0          1.55          33.4        30     3.7
    ## 4           33     36.7     39.0          1.55          33.4        30     3.7
    ## 5           21     35.1     36.7          0.10           5.9       100     8.8
    ## 6           21     35.1     36.7          0.10           5.9       100     8.8
    ##   WBC_max id2 tstart Days Status tgroup
    ## 1    13.1   1      0   90      0      1
    ## 2    13.1   1     90 2408      0      2
    ## 3     4.2   2      0   90      0      1
    ## 4     4.2   2     90 2408      0      2
    ## 5    11.5   3      0   90      0      1
    ## 6    11.5   3     90  575      1      2
    # Fit the model with time x covariate interactions
    ICU.mv_reduced4.split <- coxph(Surv(Days, Status) ~
                                    Age + ICUType:strata(tgroup) + 
                                    Albumin_min:strata(tgroup) + 
                                    Bilirubin_max:strata(tgroup) + BUN_max + 
                                    GCS_max:strata(tgroup) + HCO3_min:strata(tgroup) + 
                                    HR_min:strata(tgroup) + 
                                    Lactate_max:strata(tgroup) + Na_max + pH_min + 
                                    Temp_max + Urine_min,
                                    data = ICU.split)
    summary(ICU.mv_reduced4.split)
    ## Call:
    ## coxph(formula = Surv(Days, Status) ~ Age + ICUType:strata(tgroup) + 
    ##     Albumin_min:strata(tgroup) + Bilirubin_max:strata(tgroup) + 
    ##     BUN_max + GCS_max:strata(tgroup) + HCO3_min:strata(tgroup) + 
    ##     HR_min:strata(tgroup) + Lactate_max:strata(tgroup) + Na_max + 
    ##     pH_min + Temp_max + Urine_min, data = ICU.split)
    ## 
    ##   n= 3448, number of events= 721 
    ## 
    ##                                                                   coef
    ## Age                                                          0.0346090
    ## BUN_max                                                      0.0102853
    ## Na_max                                                      -0.0373177
    ## pH_min                                                      -0.4234153
    ## Temp_max                                                    -0.1532807
    ## Urine_min                                                   -0.0018609
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=1             0.0334824
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=1 -1.1587488
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=1                    0.1907664
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=1                          NA
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=2             0.0755461
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=2 -0.3034695
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=2                    0.5346959
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=2                          NA
    ## strata(tgroup)tgroup=1:Albumin_min                          -0.2316071
    ## strata(tgroup)tgroup=2:Albumin_min                           0.0295442
    ## strata(tgroup)tgroup=1:Bilirubin_max                         0.0294162
    ## strata(tgroup)tgroup=2:Bilirubin_max                        -0.0166200
    ## strata(tgroup)tgroup=1:GCS_max                              -0.1284553
    ## strata(tgroup)tgroup=2:GCS_max                              -0.0686016
    ## strata(tgroup)tgroup=1:HCO3_min                             -0.0017832
    ## strata(tgroup)tgroup=2:HCO3_min                              0.0399073
    ## strata(tgroup)tgroup=1:HR_min                                0.0092707
    ## strata(tgroup)tgroup=2:HR_min                                0.0021339
    ## strata(tgroup)tgroup=1:Lactate_max                           0.0847352
    ## strata(tgroup)tgroup=2:Lactate_max                          -0.0122143
    ##                                                              exp(coef)
    ## Age                                                          1.0352149
    ## BUN_max                                                      1.0103384
    ## Na_max                                                       0.9633700
    ## pH_min                                                       0.6548066
    ## Temp_max                                                     0.8578889
    ## Urine_min                                                    0.9981409
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=1             1.0340493
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=1  0.3138787
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=1                    1.2101767
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=1                          NA
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=2             1.0784730
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=2  0.7382524
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=2                    1.7069291
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=2                          NA
    ## strata(tgroup)tgroup=1:Albumin_min                           0.7932578
    ## strata(tgroup)tgroup=2:Albumin_min                           1.0299849
    ## strata(tgroup)tgroup=1:Bilirubin_max                         1.0298531
    ## strata(tgroup)tgroup=2:Bilirubin_max                         0.9835173
    ## strata(tgroup)tgroup=1:GCS_max                               0.8794529
    ## strata(tgroup)tgroup=2:GCS_max                               0.9336986
    ## strata(tgroup)tgroup=1:HCO3_min                              0.9982184
    ## strata(tgroup)tgroup=2:HCO3_min                              1.0407143
    ## strata(tgroup)tgroup=1:HR_min                                1.0093138
    ## strata(tgroup)tgroup=2:HR_min                                1.0021362
    ## strata(tgroup)tgroup=1:Lactate_max                           1.0884289
    ## strata(tgroup)tgroup=2:Lactate_max                           0.9878600
    ##                                                               se(coef)      z
    ## Age                                                          0.0027578 12.550
    ## BUN_max                                                      0.0013839  7.432
    ## Na_max                                                       0.0078838 -4.733
    ## pH_min                                                       0.1948427 -2.173
    ## Temp_max                                                     0.0519571 -2.950
    ## Urine_min                                                    0.0009391 -1.982
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=1             0.1693702  0.198
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=1  0.2046760 -5.661
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=1                    0.1313555  1.452
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=1                   0.0000000     NA
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=2             0.1898386  0.398
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=2  0.1780409 -1.704
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=2                    0.1497039  3.572
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=2                   0.0000000     NA
    ## strata(tgroup)tgroup=1:Albumin_min                           0.0876911 -2.641
    ## strata(tgroup)tgroup=2:Albumin_min                           0.0932320  0.317
    ## strata(tgroup)tgroup=1:Bilirubin_max                         0.0081990  3.588
    ## strata(tgroup)tgroup=2:Bilirubin_max                         0.0176978 -0.939
    ## strata(tgroup)tgroup=1:GCS_max                               0.0157474 -8.157
    ## strata(tgroup)tgroup=2:GCS_max                               0.0190971 -3.592
    ## strata(tgroup)tgroup=1:HCO3_min                              0.0116061 -0.154
    ## strata(tgroup)tgroup=2:HCO3_min                              0.0122847  3.249
    ## strata(tgroup)tgroup=1:HR_min                                0.0032363  2.865
    ## strata(tgroup)tgroup=2:HR_min                                0.0038392  0.556
    ## strata(tgroup)tgroup=1:Lactate_max                           0.0205997  4.113
    ## strata(tgroup)tgroup=2:Lactate_max                           0.0345008 -0.354
    ##                                                                         Pr(>|z|)
    ## Age                                                         < 0.0000000000000002
    ## BUN_max                                                     0.000000000000107052
    ## Na_max                                                      0.000002207204558216
    ## pH_min                                                                  0.029772
    ## Temp_max                                                                0.003176
    ## Urine_min                                                               0.047532
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=1                        0.843289
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=1 0.000000015015891605
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=1                               0.146421
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=1                                    NA
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=2                        0.690668
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=2             0.088289
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=2                               0.000355
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=2                                    NA
    ## strata(tgroup)tgroup=1:Albumin_min                                      0.008262
    ## strata(tgroup)tgroup=2:Albumin_min                                      0.751328
    ## strata(tgroup)tgroup=1:Bilirubin_max                                    0.000334
    ## strata(tgroup)tgroup=2:Bilirubin_max                                    0.347680
    ## strata(tgroup)tgroup=1:GCS_max                              0.000000000000000343
    ## strata(tgroup)tgroup=2:GCS_max                                          0.000328
    ## strata(tgroup)tgroup=1:HCO3_min                                         0.877893
    ## strata(tgroup)tgroup=2:HCO3_min                                         0.001160
    ## strata(tgroup)tgroup=1:HR_min                                           0.004176
    ## strata(tgroup)tgroup=2:HR_min                                           0.578339
    ## strata(tgroup)tgroup=1:Lactate_max                          0.000038982884543304
    ## strata(tgroup)tgroup=2:Lactate_max                                      0.723318
    ##                                                                
    ## Age                                                         ***
    ## BUN_max                                                     ***
    ## Na_max                                                      ***
    ## pH_min                                                      *  
    ## Temp_max                                                    ** 
    ## Urine_min                                                   *  
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=1               
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=1 ***
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=1                      
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=1                     
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=2               
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=2 .  
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=2                   ***
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=2                     
    ## strata(tgroup)tgroup=1:Albumin_min                          ** 
    ## strata(tgroup)tgroup=2:Albumin_min                             
    ## strata(tgroup)tgroup=1:Bilirubin_max                        ***
    ## strata(tgroup)tgroup=2:Bilirubin_max                           
    ## strata(tgroup)tgroup=1:GCS_max                              ***
    ## strata(tgroup)tgroup=2:GCS_max                              ***
    ## strata(tgroup)tgroup=1:HCO3_min                                
    ## strata(tgroup)tgroup=2:HCO3_min                             ** 
    ## strata(tgroup)tgroup=1:HR_min                               ** 
    ## strata(tgroup)tgroup=2:HR_min                                  
    ## strata(tgroup)tgroup=1:Lactate_max                          ***
    ## strata(tgroup)tgroup=2:Lactate_max                             
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ##                                                             exp(coef)
    ## Age                                                            1.0352
    ## BUN_max                                                        1.0103
    ## Na_max                                                         0.9634
    ## pH_min                                                         0.6548
    ## Temp_max                                                       0.8579
    ## Urine_min                                                      0.9981
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=1               1.0340
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=1    0.3139
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=1                      1.2102
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=1                         NA
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=2               1.0785
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=2    0.7383
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=2                      1.7069
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=2                         NA
    ## strata(tgroup)tgroup=1:Albumin_min                             0.7933
    ## strata(tgroup)tgroup=2:Albumin_min                             1.0300
    ## strata(tgroup)tgroup=1:Bilirubin_max                           1.0299
    ## strata(tgroup)tgroup=2:Bilirubin_max                           0.9835
    ## strata(tgroup)tgroup=1:GCS_max                                 0.8795
    ## strata(tgroup)tgroup=2:GCS_max                                 0.9337
    ## strata(tgroup)tgroup=1:HCO3_min                                0.9982
    ## strata(tgroup)tgroup=2:HCO3_min                                1.0407
    ## strata(tgroup)tgroup=1:HR_min                                  1.0093
    ## strata(tgroup)tgroup=2:HR_min                                  1.0021
    ## strata(tgroup)tgroup=1:Lactate_max                             1.0884
    ## strata(tgroup)tgroup=2:Lactate_max                             0.9879
    ##                                                             exp(-coef)
    ## Age                                                             0.9660
    ## BUN_max                                                         0.9898
    ## Na_max                                                          1.0380
    ## pH_min                                                          1.5272
    ## Temp_max                                                        1.1657
    ## Urine_min                                                       1.0019
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=1                0.9671
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=1     3.1859
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=1                       0.8263
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=1                          NA
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=2                0.9272
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=2     1.3546
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=2                       0.5858
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=2                          NA
    ## strata(tgroup)tgroup=1:Albumin_min                              1.2606
    ## strata(tgroup)tgroup=2:Albumin_min                              0.9709
    ## strata(tgroup)tgroup=1:Bilirubin_max                            0.9710
    ## strata(tgroup)tgroup=2:Bilirubin_max                            1.0168
    ## strata(tgroup)tgroup=1:GCS_max                                  1.1371
    ## strata(tgroup)tgroup=2:GCS_max                                  1.0710
    ## strata(tgroup)tgroup=1:HCO3_min                                 1.0018
    ## strata(tgroup)tgroup=2:HCO3_min                                 0.9609
    ## strata(tgroup)tgroup=1:HR_min                                   0.9908
    ## strata(tgroup)tgroup=2:HR_min                                   0.9979
    ## strata(tgroup)tgroup=1:Lactate_max                              0.9188
    ## strata(tgroup)tgroup=2:Lactate_max                              1.0123
    ##                                                             lower .95 upper .95
    ## Age                                                            1.0296    1.0408
    ## BUN_max                                                        1.0076    1.0131
    ## Na_max                                                         0.9486    0.9784
    ## pH_min                                                         0.4470    0.9593
    ## Temp_max                                                       0.7748    0.9499
    ## Urine_min                                                      0.9963    1.0000
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=1               0.7419    1.4412
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=1    0.2102    0.4688
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=1                      0.9355    1.5655
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=1                         NA        NA
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=2               0.7434    1.5646
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=2    0.5208    1.0465
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=2                      1.2729    2.2890
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=2                         NA        NA
    ## strata(tgroup)tgroup=1:Albumin_min                             0.6680    0.9420
    ## strata(tgroup)tgroup=2:Albumin_min                             0.8580    1.2365
    ## strata(tgroup)tgroup=1:Bilirubin_max                           1.0134    1.0465
    ## strata(tgroup)tgroup=2:Bilirubin_max                           0.9500    1.0182
    ## strata(tgroup)tgroup=1:GCS_max                                 0.8527    0.9070
    ## strata(tgroup)tgroup=2:GCS_max                                 0.8994    0.9693
    ## strata(tgroup)tgroup=1:HCO3_min                                0.9758    1.0212
    ## strata(tgroup)tgroup=2:HCO3_min                                1.0160    1.0661
    ## strata(tgroup)tgroup=1:HR_min                                  1.0029    1.0157
    ## strata(tgroup)tgroup=2:HR_min                                  0.9946    1.0097
    ## strata(tgroup)tgroup=1:Lactate_max                             1.0454    1.1333
    ## strata(tgroup)tgroup=2:Lactate_max                             0.9233    1.0570
    ## 
    ## Concordance= 0.748  (se = 0.009 )
    ## Likelihood ratio test= 564.7  on 24 df,   p=<0.0000000000000002
    ## Wald test            = 544.8  on 24 df,   p=<0.0000000000000002
    ## Score (logrank) test = 593.4  on 24 df,   p=<0.0000000000000002
    # evaluating the proportional hazards assumption again, for the model with time x covariate interactions
    cox.zph(ICU.mv_reduced4.split, terms=FALSE)
    ##                                                                chisq df      p
    ## Age                                                          0.16638  1 0.6833
    ## BUN_max                                                      0.02835  1 0.8663
    ## Na_max                                                       0.52712  1 0.4678
    ## pH_min                                                       0.20377  1 0.6517
    ## Temp_max                                                     0.36572  1 0.5453
    ## Urine_min                                                    1.64748  1 0.1993
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=1             0.00282  1 0.9576
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=1  0.68770  1 0.4069
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=1                    0.00532  1 0.9419
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=2             0.11821  1 0.7310
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=2  2.10958  1 0.1464
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=2                    0.58893  1 0.4428
    ## strata(tgroup)tgroup=1:Albumin_min                           2.32455  1 0.1273
    ## strata(tgroup)tgroup=2:Albumin_min                           0.00195  1 0.9648
    ## strata(tgroup)tgroup=1:Bilirubin_max                         0.92725  1 0.3356
    ## strata(tgroup)tgroup=2:Bilirubin_max                         3.38839  1 0.0657
    ## strata(tgroup)tgroup=1:GCS_max                              10.61588  1 0.0011
    ## strata(tgroup)tgroup=2:GCS_max                               2.53281  1 0.1115
    ## strata(tgroup)tgroup=1:HCO3_min                              4.83676  1 0.0279
    ## strata(tgroup)tgroup=2:HCO3_min                              1.56563  1 0.2108
    ## strata(tgroup)tgroup=1:HR_min                                0.97301  1 0.3239
    ## strata(tgroup)tgroup=2:HR_min                                0.32407  1 0.5692
    ## strata(tgroup)tgroup=1:Lactate_max                           5.00208  1 0.0253
    ## strata(tgroup)tgroup=2:Lactate_max                           5.91846  1 0.0150
    ## GLOBAL                                                      35.16653 24 0.0660
    ## Result: the global test is now insignificant (p = 0.07)
    
    
    # Checking Linearity by observing Martingale residuals
    
    # Refit the chosen model with any factor variables re-coded as numeric 
    # to allow the ggcoxfunctional() function to work
    ICU.mv_reduced4.nofactor <- coxph(Surv(Days, Status) ~
                                      Age + as.numeric(ICUType) + Albumin_min + Bilirubin_max + BUN_max + 
                                      GCS_max + HCO3_min + HR_min + Lactate_max + Na_max + 
                                      pH_min + Temp_max + Urine_min,
                                      data = nm_icu_model_df1)
    ggcoxfunctional(ICU.mv_reduced4.nofactor, nm_icu_model_df1)

    ## Result: they don't look particularly linear... especially with laboratory values very far from the reference ranges 
    ##         (likely few observations in this range / potential outliers)
    
    
    # Check linearity of the model as a whole
    ggcoxdiagnostics(ICU.mv_reduced4, type = "martingale", linear.predictions = FALSE, ggtheme = theme_bw()) 
    ## `geom_smooth()` using formula 'y ~ x'

    ## Result: appears reasonably linear with with 2 large negative outliers 
    ##         (large negative interpretation = 'lived too long')
    
    # Examine the observations with very large negative residuals (< -3)
    resid(ICU.mv_reduced4)[resid(ICU.mv_reduced4) < -3]
    ##      1511      1929 
    ## -4.197771 -3.207614
    icu_patients_df1[c(1511,1929),]
    ##      RecordID Length_of_stay SAPS1 SOFA Survival in_hospital_death Days Status
    ## 1511   136398             51    22   10       NA                 0 2408  FALSE
    ## 1929   137433             23    NA    7       NA                 0 2408  FALSE
    ##      Age Albumin_diff Albumin_max Albumin_min ALP_diff ALP_max ALP_min ALT_diff
    ## 1511  70    0.0186633         3.0         3.0 50.85204      45      74 105.4462
    ## 1929  78    0.6813367         2.3         2.3 57.14796     153     153 138.5538
    ##      ALT_max ALT_min AST_diff AST_max AST_min Bilirubin_diff Bilirubin_max
    ## 1511      40      15 151.3527      18      57       1.364039           0.9
    ## 1929     259     259 203.6473     373     373       4.935961           6.7
    ##      Bilirubin_min BUN_diff BUN_max BUN_min Cholesterol_diff Cholesterol_max
    ## 1511           0.4 99.47295     124     120         9.422764             147
    ## 1929           6.7 97.47295     122     122        81.422764              75
    ##      Cholesterol_min Creatinine_diff Creatinine_max Creatinine_min DiasABP_diff
    ## 1511             147        5.167554            6.4            5.8     11.54421
    ## 1929             101        2.967554            4.2            4.2           NA
    ##      DiasABP_max DiasABP_min FiO2_diff FiO2_max FiO2_min GCS_diff GCS_max
    ## 1511          67          47 0.4480799        1      0.4 6.244029       9
    ## 1929          NA          NA 0.4480799        1      1.0 3.755971      15
    ##      GCS_min Gender Glucose_diff Glucose_max Glucose_min HCO3_diff HCO3_max
    ## 1511       5 Female    142.14446         282          41 15.772548       10
    ## 1929      15   Male     66.85554          73          73  0.772548       22
    ##      HCO3_min  HCT_diff HCT_max HCT_min Height  HR_diff HR_max HR_min
    ## 1511        7 10.460129    31.5    20.5  165.1 45.07789     70     42
    ## 1929       22  4.760129    26.2    26.2  177.8 27.07789     65     60
    ##          ICUType    K_diff K_max K_min Lactate_diff Lactate_max Lactate_min
    ## 1511 Medical ICU 0.6352066   3.9   3.5     4.803596         7.6         7.6
    ## 1929 Medical ICU 0.1352066   4.0   4.0     2.203596         5.0         1.6
    ##       MAP_diff MAP_max MAP_min   Mg_diff Mg_max Mg_min  Na_diff Na_max Na_min
    ## 1511 120.23164     198      55 0.1842982    2.0    1.8 8.206607    133    131
    ## 1929  19.76836      58      65 0.6157018    2.6    2.6 6.206607    133    133
    ##      NIDiasABP_diff NIDiasABP_max NIDiasABP_min NIMAP_diff NIMAP_max NIMAP_min
    ## 1511       20.49101            72            37   21.38069     84.67     54.33
    ## 1929       31.49101            82            26   24.04069     93.00     51.67
    ##      NISysABP_diff NISysABP_max NISysABP_min PaCO2_diff PaCO2_max PaCO2_min
    ## 1511      37.69875          126           79  25.335797        22        15
    ## 1929      18.69875          119           98   4.335797        40        36
    ##      PaO2_diff PaO2_max PaO2_min    pH_diff pH_max pH_min Platelets_diff
    ## 1511  282.3821      441      120 0.14988624   7.31   7.22       77.76931
    ## 1929  108.6179      107       50 0.07988624   7.31   7.29      154.23069
    ##      Platelets_max Platelets_min RespRate_diff RespRate_max RespRate_min
    ## 1511           150           112      10.65142           30           10
    ## 1929           344           344      11.65142           31           17
    ##      SaO2_diff SaO2_max SaO2_min SysABP_diff SysABP_max SysABP_min Temp_diff
    ## 1511 0.7539211       98       98     42.3105        126         74  2.574083
    ## 1929 2.2460789       99       95          NA         NA         NA  1.174083
    ##      Temp_max Temp_min TroponinI_diff TroponinI_max TroponinI_min
    ## 1511     36.1     34.4       1.542945           3.9           3.9
    ## 1929     37.9     35.8       3.742945           3.9           1.7
    ##      TroponinT_diff TroponinT_max TroponinT_min Urine_diff Urine_max Urine_min
    ## 1511      0.6185006          0.27          0.05   99.21758        70         0
    ## 1929      3.3414994          4.01          1.67   99.21758       120         0
    ##       WBC_diff WBC_max WBC_min Weight_diff Weight_max Weight_min PFratio
    ## 1511 3.7331524     9.8     8.4    2.499878       78.2       78.2     120
    ## 1929 0.6668476    12.8    12.8    4.699878       76.0       76.0      50
    ## Interpretation: looks like they were relatively elderly with long lengths of stay
    ##                - one had low GCS values/high SAPS1/high lactate
    ##                - the other had high bilirubin/deranged LFTs/high lactate
    
    ## Decision: remove these outliers and re-fit the model to the dataset excluding these observations -->
    
    # Check the RecordIDs match up with the correct data in the non-missing, split dataset
    ICU.split[(ICU.split$RecordID == 136398 | ICU.split$RecordID == 137433),]
    ##      RecordID in_hospital_death Age Gender     ICUType Weight_max Albumin_min
    ## 2512   136398                 0  70 Female Medical ICU       78.2         3.0
    ## 2513   136398                 0  70 Female Medical ICU       78.2         3.0
    ## 3226   137433                 0  78   Male Medical ICU       76.0         2.3
    ## 3227   137433                 0  78   Male Medical ICU       76.0         2.3
    ##      Bilirubin_max BUN_max Creatinine_max GCS_max Glucose_min Glucose_max
    ## 2512           0.9     124            6.4       9          41         282
    ## 2513           0.9     124            6.4       9          41         282
    ## 3226           6.7     122            4.2      15          73          73
    ## 3227           6.7     122            4.2      15          73          73
    ##      HCO3_min HR_min HR_max K_min K_max Lactate_max MAP_min Na_min Na_max
    ## 2512        7     42     70   3.5   3.9         7.6      55    131    133
    ## 2513        7     42     70   3.5   3.9         7.6      55    131    133
    ## 3226       22     60     65   4.0   4.0         5.0      65    133    133
    ## 3227       22     60     65   4.0   4.0         5.0      65    133    133
    ##      Platelets_min PFratio pH_min pH_max RespRate_min RespRate_max Temp_min
    ## 2512           112     120   7.22   7.31           10           30     34.4
    ## 2513           112     120   7.22   7.31           10           30     34.4
    ## 3226           344      50   7.29   7.31           17           31     35.8
    ## 3227           344      50   7.29   7.31           17           31     35.8
    ##      Temp_max TroponinT_max TroponinI_max Urine_min WBC_min WBC_max  id2 tstart
    ## 2512     36.1          0.27           3.9         0     8.4     9.8 1400      0
    ## 2513     36.1          0.27           3.9         0     8.4     9.8 1400     90
    ## 3226     37.9          4.01           3.9         0    12.8    12.8 1792      0
    ## 3227     37.9          4.01           3.9         0    12.8    12.8 1792     90
    ##      Days Status tgroup
    ## 2512   90      0      1
    ## 2513 2408      0      2
    ## 3226   90      0      1
    ## 3227 2408      0      2
    # Remove these observations and save as new dataset
    ICU.split_noutliers <- ICU.split[!(ICU.split$RecordID %in% c(136398, 137433)),]
    
    # Refit the split model to the new dataset
    ICU.mv_reduced4.split.noutliers <- coxph(Surv(Days, Status) ~
                                              Age + ICUType:strata(tgroup) + 
                                              Albumin_min:strata(tgroup) + 
                                              Bilirubin_max:strata(tgroup) + BUN_max + 
                                              GCS_max:strata(tgroup) + HCO3_min:strata(tgroup) + 
                                              HR_min:strata(tgroup) + 
                                              Lactate_max:strata(tgroup) + Na_max + pH_min + 
                                              Temp_max + Urine_min,
                                              data = ICU.split_noutliers)
    summary(ICU.mv_reduced4.split.noutliers)
    ## Call:
    ## coxph(formula = Surv(Days, Status) ~ Age + ICUType:strata(tgroup) + 
    ##     Albumin_min:strata(tgroup) + Bilirubin_max:strata(tgroup) + 
    ##     BUN_max + GCS_max:strata(tgroup) + HCO3_min:strata(tgroup) + 
    ##     HR_min:strata(tgroup) + Lactate_max:strata(tgroup) + Na_max + 
    ##     pH_min + Temp_max + Urine_min, data = ICU.split_noutliers)
    ## 
    ##   n= 3444, number of events= 721 
    ## 
    ##                                                                   coef
    ## Age                                                          0.0345124
    ## BUN_max                                                      0.0111342
    ## Na_max                                                      -0.0404555
    ## pH_min                                                      -0.4124840
    ## Temp_max                                                    -0.1582918
    ## Urine_min                                                   -0.0019812
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=1             0.0221166
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=1 -1.1586329
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=1                    0.2008633
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=1                          NA
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=2             0.0655282
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=2 -0.3071060
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=2                    0.5463547
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=2                          NA
    ## strata(tgroup)tgroup=1:Albumin_min                          -0.2312474
    ## strata(tgroup)tgroup=2:Albumin_min                           0.0257121
    ## strata(tgroup)tgroup=1:Bilirubin_max                         0.0287543
    ## strata(tgroup)tgroup=2:Bilirubin_max                        -0.0159728
    ## strata(tgroup)tgroup=1:GCS_max                              -0.1281817
    ## strata(tgroup)tgroup=2:GCS_max                              -0.0686489
    ## strata(tgroup)tgroup=1:HCO3_min                             -0.0033246
    ## strata(tgroup)tgroup=2:HCO3_min                              0.0391071
    ## strata(tgroup)tgroup=1:HR_min                                0.0081504
    ## strata(tgroup)tgroup=2:HR_min                                0.0013052
    ## strata(tgroup)tgroup=1:Lactate_max                           0.0904054
    ## strata(tgroup)tgroup=2:Lactate_max                          -0.0013510
    ##                                                              exp(coef)
    ## Age                                                          1.0351149
    ## BUN_max                                                      1.0111965
    ## Na_max                                                       0.9603519
    ## pH_min                                                       0.6620038
    ## Temp_max                                                     0.8536006
    ## Urine_min                                                    0.9980208
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=1             1.0223630
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=1  0.3139150
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=1                    1.2224577
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=1                          NA
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=2             1.0677228
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=2  0.7355726
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=2                    1.7269462
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=2                          NA
    ## strata(tgroup)tgroup=1:Albumin_min                           0.7935431
    ## strata(tgroup)tgroup=2:Albumin_min                           1.0260455
    ## strata(tgroup)tgroup=1:Bilirubin_max                         1.0291717
    ## strata(tgroup)tgroup=2:Bilirubin_max                         0.9841541
    ## strata(tgroup)tgroup=1:GCS_max                               0.8796935
    ## strata(tgroup)tgroup=2:GCS_max                               0.9336545
    ## strata(tgroup)tgroup=1:HCO3_min                              0.9966809
    ## strata(tgroup)tgroup=2:HCO3_min                              1.0398819
    ## strata(tgroup)tgroup=1:HR_min                                1.0081837
    ## strata(tgroup)tgroup=2:HR_min                                1.0013060
    ## strata(tgroup)tgroup=1:Lactate_max                           1.0946180
    ## strata(tgroup)tgroup=2:Lactate_max                           0.9986499
    ##                                                               se(coef)      z
    ## Age                                                          0.0027499 12.550
    ## BUN_max                                                      0.0013776  8.082
    ## Na_max                                                       0.0078816 -5.133
    ## pH_min                                                       0.1978059 -2.085
    ## Temp_max                                                     0.0521644 -3.034
    ## Urine_min                                                    0.0009464 -2.093
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=1             0.1694156  0.131
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=1  0.2047092 -5.660
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=1                    0.1311915  1.531
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=1                   0.0000000     NA
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=2             0.1898951  0.345
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=2  0.1780033 -1.725
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=2                    0.1496993  3.650
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=2                   0.0000000     NA
    ## strata(tgroup)tgroup=1:Albumin_min                           0.0875372 -2.642
    ## strata(tgroup)tgroup=2:Albumin_min                           0.0932299  0.276
    ## strata(tgroup)tgroup=1:Bilirubin_max                         0.0081724  3.518
    ## strata(tgroup)tgroup=2:Bilirubin_max                         0.0173879 -0.919
    ## strata(tgroup)tgroup=1:GCS_max                               0.0157330 -8.147
    ## strata(tgroup)tgroup=2:GCS_max                               0.0190784 -3.598
    ## strata(tgroup)tgroup=1:HCO3_min                              0.0117341 -0.283
    ## strata(tgroup)tgroup=2:HCO3_min                              0.0123778  3.159
    ## strata(tgroup)tgroup=1:HR_min                                0.0032554  2.504
    ## strata(tgroup)tgroup=2:HR_min                                0.0038581  0.338
    ## strata(tgroup)tgroup=1:Lactate_max                           0.0202818  4.457
    ## strata(tgroup)tgroup=2:Lactate_max                           0.0342960 -0.039
    ##                                                                         Pr(>|z|)
    ## Age                                                         < 0.0000000000000002
    ## BUN_max                                                     0.000000000000000636
    ## Na_max                                                      0.000000285293278950
    ## pH_min                                                                  0.037042
    ## Temp_max                                                                0.002410
    ## Urine_min                                                               0.036316
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=1                        0.896134
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=1 0.000000015146402643
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=1                               0.125752
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=1                                    NA
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=2                        0.730037
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=2             0.084477
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=2                               0.000263
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=2                                    NA
    ## strata(tgroup)tgroup=1:Albumin_min                                      0.008249
    ## strata(tgroup)tgroup=2:Albumin_min                                      0.782708
    ## strata(tgroup)tgroup=1:Bilirubin_max                                    0.000434
    ## strata(tgroup)tgroup=2:Bilirubin_max                                    0.358295
    ## strata(tgroup)tgroup=1:GCS_max                              0.000000000000000372
    ## strata(tgroup)tgroup=2:GCS_max                                          0.000320
    ## strata(tgroup)tgroup=1:HCO3_min                                         0.776925
    ## strata(tgroup)tgroup=2:HCO3_min                                         0.001581
    ## strata(tgroup)tgroup=1:HR_min                                           0.012291
    ## strata(tgroup)tgroup=2:HR_min                                           0.735142
    ## strata(tgroup)tgroup=1:Lactate_max                          0.000008293318325089
    ## strata(tgroup)tgroup=2:Lactate_max                                      0.968577
    ##                                                                
    ## Age                                                         ***
    ## BUN_max                                                     ***
    ## Na_max                                                      ***
    ## pH_min                                                      *  
    ## Temp_max                                                    ** 
    ## Urine_min                                                   *  
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=1               
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=1 ***
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=1                      
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=1                     
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=2               
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=2 .  
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=2                   ***
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=2                     
    ## strata(tgroup)tgroup=1:Albumin_min                          ** 
    ## strata(tgroup)tgroup=2:Albumin_min                             
    ## strata(tgroup)tgroup=1:Bilirubin_max                        ***
    ## strata(tgroup)tgroup=2:Bilirubin_max                           
    ## strata(tgroup)tgroup=1:GCS_max                              ***
    ## strata(tgroup)tgroup=2:GCS_max                              ***
    ## strata(tgroup)tgroup=1:HCO3_min                                
    ## strata(tgroup)tgroup=2:HCO3_min                             ** 
    ## strata(tgroup)tgroup=1:HR_min                               *  
    ## strata(tgroup)tgroup=2:HR_min                                  
    ## strata(tgroup)tgroup=1:Lactate_max                          ***
    ## strata(tgroup)tgroup=2:Lactate_max                             
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ##                                                             exp(coef)
    ## Age                                                            1.0351
    ## BUN_max                                                        1.0112
    ## Na_max                                                         0.9604
    ## pH_min                                                         0.6620
    ## Temp_max                                                       0.8536
    ## Urine_min                                                      0.9980
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=1               1.0224
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=1    0.3139
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=1                      1.2225
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=1                         NA
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=2               1.0677
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=2    0.7356
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=2                      1.7269
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=2                         NA
    ## strata(tgroup)tgroup=1:Albumin_min                             0.7935
    ## strata(tgroup)tgroup=2:Albumin_min                             1.0260
    ## strata(tgroup)tgroup=1:Bilirubin_max                           1.0292
    ## strata(tgroup)tgroup=2:Bilirubin_max                           0.9842
    ## strata(tgroup)tgroup=1:GCS_max                                 0.8797
    ## strata(tgroup)tgroup=2:GCS_max                                 0.9337
    ## strata(tgroup)tgroup=1:HCO3_min                                0.9967
    ## strata(tgroup)tgroup=2:HCO3_min                                1.0399
    ## strata(tgroup)tgroup=1:HR_min                                  1.0082
    ## strata(tgroup)tgroup=2:HR_min                                  1.0013
    ## strata(tgroup)tgroup=1:Lactate_max                             1.0946
    ## strata(tgroup)tgroup=2:Lactate_max                             0.9986
    ##                                                             exp(-coef)
    ## Age                                                             0.9661
    ## BUN_max                                                         0.9889
    ## Na_max                                                          1.0413
    ## pH_min                                                          1.5106
    ## Temp_max                                                        1.1715
    ## Urine_min                                                       1.0020
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=1                0.9781
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=1     3.1856
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=1                       0.8180
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=1                          NA
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=2                0.9366
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=2     1.3595
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=2                       0.5791
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=2                          NA
    ## strata(tgroup)tgroup=1:Albumin_min                              1.2602
    ## strata(tgroup)tgroup=2:Albumin_min                              0.9746
    ## strata(tgroup)tgroup=1:Bilirubin_max                            0.9717
    ## strata(tgroup)tgroup=2:Bilirubin_max                            1.0161
    ## strata(tgroup)tgroup=1:GCS_max                                  1.1368
    ## strata(tgroup)tgroup=2:GCS_max                                  1.0711
    ## strata(tgroup)tgroup=1:HCO3_min                                 1.0033
    ## strata(tgroup)tgroup=2:HCO3_min                                 0.9616
    ## strata(tgroup)tgroup=1:HR_min                                   0.9919
    ## strata(tgroup)tgroup=2:HR_min                                   0.9987
    ## strata(tgroup)tgroup=1:Lactate_max                              0.9136
    ## strata(tgroup)tgroup=2:Lactate_max                              1.0014
    ##                                                             lower .95 upper .95
    ## Age                                                            1.0296    1.0407
    ## BUN_max                                                        1.0085    1.0139
    ## Na_max                                                         0.9456    0.9753
    ## pH_min                                                         0.4492    0.9755
    ## Temp_max                                                       0.7706    0.9455
    ## Urine_min                                                      0.9962    0.9999
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=1               0.7335    1.4250
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=1    0.2102    0.4689
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=1                      0.9453    1.5809
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=1                         NA        NA
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=2               0.7359    1.5492
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=2    0.5189    1.0427
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=2                      1.2878    2.3158
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=2                         NA        NA
    ## strata(tgroup)tgroup=1:Albumin_min                             0.6684    0.9421
    ## strata(tgroup)tgroup=2:Albumin_min                             0.8547    1.2318
    ## strata(tgroup)tgroup=1:Bilirubin_max                           1.0128    1.0458
    ## strata(tgroup)tgroup=2:Bilirubin_max                           0.9512    1.0183
    ## strata(tgroup)tgroup=1:GCS_max                                 0.8530    0.9072
    ## strata(tgroup)tgroup=2:GCS_max                                 0.8994    0.9692
    ## strata(tgroup)tgroup=1:HCO3_min                                0.9740    1.0199
    ## strata(tgroup)tgroup=2:HCO3_min                                1.0150    1.0654
    ## strata(tgroup)tgroup=1:HR_min                                  1.0018    1.0146
    ## strata(tgroup)tgroup=2:HR_min                                  0.9938    1.0089
    ## strata(tgroup)tgroup=1:Lactate_max                             1.0520    1.1390
    ## strata(tgroup)tgroup=2:Lactate_max                             0.9337    1.0681
    ## 
    ## Concordance= 0.749  (se = 0.009 )
    ## Likelihood ratio test= 577.1  on 24 df,   p=<0.0000000000000002
    ## Wald test            = 558.2  on 24 df,   p=<0.0000000000000002
    ## Score (logrank) test = 607.6  on 24 df,   p=<0.0000000000000002
    # Calculate the split/no outlier model AIC
    AIC.mv_reduced4.split.noutliers <- calc_aic(ICU.mv_reduced4.split.noutliers)
    AIC.mv_reduced4.split.noutliers #10057 -- improvement
    ## [1] 10057.49
    ## Decision: use the 4th reduced model, split at time 3 months (90 days) on the split dataset with the outliers removed as the final dataset
    
    # Difference in Coefficients
    ICU.mv_reduced4.split.noutliers$coefficients
    ##                                                         Age 
    ##                                                 0.034512415 
    ##                                                     BUN_max 
    ##                                                 0.011134243 
    ##                                                      Na_max 
    ##                                                -0.040455500 
    ##                                                      pH_min 
    ##                                                -0.412483973 
    ##                                                    Temp_max 
    ##                                                -0.158291825 
    ##                                                   Urine_min 
    ##                                                -0.001981208 
    ##            ICUTypeCoronary Care Unit:strata(tgroup)tgroup=1 
    ##                                                 0.022116637 
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=1 
    ##                                                -1.158632885 
    ##                   ICUTypeMedical ICU:strata(tgroup)tgroup=1 
    ##                                                 0.200863301 
    ##                  ICUTypeSurgical ICU:strata(tgroup)tgroup=1 
    ##                                                          NA 
    ##            ICUTypeCoronary Care Unit:strata(tgroup)tgroup=2 
    ##                                                 0.065528200 
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=2 
    ##                                                -0.307105991 
    ##                   ICUTypeMedical ICU:strata(tgroup)tgroup=2 
    ##                                                 0.546354668 
    ##                  ICUTypeSurgical ICU:strata(tgroup)tgroup=2 
    ##                                                          NA 
    ##                          strata(tgroup)tgroup=1:Albumin_min 
    ##                                                -0.231247368 
    ##                          strata(tgroup)tgroup=2:Albumin_min 
    ##                                                 0.025712052 
    ##                        strata(tgroup)tgroup=1:Bilirubin_max 
    ##                                                 0.028754332 
    ##                        strata(tgroup)tgroup=2:Bilirubin_max 
    ##                                                -0.015972822 
    ##                              strata(tgroup)tgroup=1:GCS_max 
    ##                                                -0.128181712 
    ##                              strata(tgroup)tgroup=2:GCS_max 
    ##                                                -0.068648865 
    ##                             strata(tgroup)tgroup=1:HCO3_min 
    ##                                                -0.003324595 
    ##                             strata(tgroup)tgroup=2:HCO3_min 
    ##                                                 0.039107123 
    ##                               strata(tgroup)tgroup=1:HR_min 
    ##                                                 0.008150402 
    ##                               strata(tgroup)tgroup=2:HR_min 
    ##                                                 0.001305155 
    ##                          strata(tgroup)tgroup=1:Lactate_max 
    ##                                                 0.090405433 
    ##                          strata(tgroup)tgroup=2:Lactate_max 
    ##                                                -0.001351005
    ICU.mv_reduced4$coefficients
    ##                                  Age ICUTypeCardiac Surgery Recovery Unit 
    ##                          0.035038790                         -0.750679504 
    ##                   ICUTypeMedical ICU                  ICUTypeSurgical ICU 
    ##                          0.296653600                         -0.048997022 
    ##                          Albumin_min                        Bilirubin_max 
    ##                         -0.097502837                          0.017685740 
    ##                              BUN_max                              GCS_max 
    ##                          0.010354185                         -0.102515243 
    ##                             HCO3_min                               HR_min 
    ##                          0.016951994                          0.006489375 
    ##                          Lactate_max                               Na_max 
    ##                          0.056092701                         -0.036275765 
    ##                               pH_min                             Temp_max 
    ##                         -0.468490974                         -0.153788543 
    ##                            Urine_min 
    ##                         -0.001949602

    We need to test whether the chosen model satisfies the assumptions underlying the Cox Proportional Hazards model.

    1. Testing for proportional hazards assumption
    • Proportional hazard assumption is supported by a non-significant relationship between residuals and time, while a significant relationship favours the null of non-constant hazards.

    • The output from the proportional hazards test shows that the test is statistically significant (p-value < 0.05) for ICUType, Albumin_min, Bilirubin_max, GCS_max, HCO3_min, HR_min and Lactate_max. The global test is also statistically significant (p-value is very small = 1.0e-12). Therefore, there appears to be a violation of the proportional hazards model.

    • We choose to address the violations of the proportional hazards assumption by including time x covariate interactions in the model for the variables that violated the proportional hazards assumption. By looking at the survival curve and the asusmption that there may be systematic differences in patients who survive less than or greater than 3 months after ICU admission, we choose a post ICU survival time of 90 days.

    • The hazard rate increases at varying rates for the population who survived less than 90 days. add inferences for coefficients, CI’s and hazard rates

    • Allowing the regression coefficients to differ in the two time intervals (before 90 days and after) has helped address the violation of the PH assumption. The global test for our model is no longer significant (p-value =0.07).

    1. Check linearity by observing Martingale residuals for continuous variables
    • We observe a close to linear relationship for Age, Albumin_min, Bilirubin_max, GCS_max, Lactate_max and Urine_min variables.
    • There is a clear ly non-linear relationship for BUN_max, HCO3_min, HR_min, Na-max, pH_min and Temp_max.
    • Explanation - especially with laboratory values very far from the reference ranges (likely few observations in this range / potential outliers) Can someone explain this a bit better?
    1. Checking linearity for the model as a whole
    • The overall model residuals appear reasonably linear around 0. However, we do observe 2 very large negative outliers (individuals whose actual survival time was significantly greater than estimated by the model. On closer observation, these 2 individuals were relatively elderly with long lengths of stay in hospital. One had low GCS values, high SAPS1, high lactate whilst the other had high bilirubin, deranged LFTs and high lactate, all indicators of high risk of mortality.

    • We have removed these outliers observations and re-fit the model to the dataset excluding these observations. The model fit has improved (with AIC now 10,057 compared to 10,112). The resulting changes in coefficients include: add comparison to previous inferences on coefficients, CI’s and hazard rates

    Final multivariable Cox proportional hazards model:

    ICU.final.cox <- coxph(Surv(Days, Status) ~
                             Age + ICUType:strata(tgroup) + 
                             Albumin_min:strata(tgroup) + 
                             Bilirubin_max:strata(tgroup) + BUN_max + 
                             GCS_max:strata(tgroup) + HCO3_min:strata(tgroup) + 
                             HR_min:strata(tgroup) + Lactate_max:strata(tgroup) + 
                             Na_max + pH_min + Temp_max + Urine_min,
                             data = ICU.split_noutliers)
    summary(ICU.final.cox)
    ## Call:
    ## coxph(formula = Surv(Days, Status) ~ Age + ICUType:strata(tgroup) + 
    ##     Albumin_min:strata(tgroup) + Bilirubin_max:strata(tgroup) + 
    ##     BUN_max + GCS_max:strata(tgroup) + HCO3_min:strata(tgroup) + 
    ##     HR_min:strata(tgroup) + Lactate_max:strata(tgroup) + Na_max + 
    ##     pH_min + Temp_max + Urine_min, data = ICU.split_noutliers)
    ## 
    ##   n= 3444, number of events= 721 
    ## 
    ##                                                                   coef
    ## Age                                                          0.0345124
    ## BUN_max                                                      0.0111342
    ## Na_max                                                      -0.0404555
    ## pH_min                                                      -0.4124840
    ## Temp_max                                                    -0.1582918
    ## Urine_min                                                   -0.0019812
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=1             0.0221166
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=1 -1.1586329
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=1                    0.2008633
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=1                          NA
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=2             0.0655282
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=2 -0.3071060
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=2                    0.5463547
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=2                          NA
    ## strata(tgroup)tgroup=1:Albumin_min                          -0.2312474
    ## strata(tgroup)tgroup=2:Albumin_min                           0.0257121
    ## strata(tgroup)tgroup=1:Bilirubin_max                         0.0287543
    ## strata(tgroup)tgroup=2:Bilirubin_max                        -0.0159728
    ## strata(tgroup)tgroup=1:GCS_max                              -0.1281817
    ## strata(tgroup)tgroup=2:GCS_max                              -0.0686489
    ## strata(tgroup)tgroup=1:HCO3_min                             -0.0033246
    ## strata(tgroup)tgroup=2:HCO3_min                              0.0391071
    ## strata(tgroup)tgroup=1:HR_min                                0.0081504
    ## strata(tgroup)tgroup=2:HR_min                                0.0013052
    ## strata(tgroup)tgroup=1:Lactate_max                           0.0904054
    ## strata(tgroup)tgroup=2:Lactate_max                          -0.0013510
    ##                                                              exp(coef)
    ## Age                                                          1.0351149
    ## BUN_max                                                      1.0111965
    ## Na_max                                                       0.9603519
    ## pH_min                                                       0.6620038
    ## Temp_max                                                     0.8536006
    ## Urine_min                                                    0.9980208
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=1             1.0223630
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=1  0.3139150
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=1                    1.2224577
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=1                          NA
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=2             1.0677228
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=2  0.7355726
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=2                    1.7269462
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=2                          NA
    ## strata(tgroup)tgroup=1:Albumin_min                           0.7935431
    ## strata(tgroup)tgroup=2:Albumin_min                           1.0260455
    ## strata(tgroup)tgroup=1:Bilirubin_max                         1.0291717
    ## strata(tgroup)tgroup=2:Bilirubin_max                         0.9841541
    ## strata(tgroup)tgroup=1:GCS_max                               0.8796935
    ## strata(tgroup)tgroup=2:GCS_max                               0.9336545
    ## strata(tgroup)tgroup=1:HCO3_min                              0.9966809
    ## strata(tgroup)tgroup=2:HCO3_min                              1.0398819
    ## strata(tgroup)tgroup=1:HR_min                                1.0081837
    ## strata(tgroup)tgroup=2:HR_min                                1.0013060
    ## strata(tgroup)tgroup=1:Lactate_max                           1.0946180
    ## strata(tgroup)tgroup=2:Lactate_max                           0.9986499
    ##                                                               se(coef)      z
    ## Age                                                          0.0027499 12.550
    ## BUN_max                                                      0.0013776  8.082
    ## Na_max                                                       0.0078816 -5.133
    ## pH_min                                                       0.1978059 -2.085
    ## Temp_max                                                     0.0521644 -3.034
    ## Urine_min                                                    0.0009464 -2.093
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=1             0.1694156  0.131
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=1  0.2047092 -5.660
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=1                    0.1311915  1.531
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=1                   0.0000000     NA
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=2             0.1898951  0.345
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=2  0.1780033 -1.725
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=2                    0.1496993  3.650
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=2                   0.0000000     NA
    ## strata(tgroup)tgroup=1:Albumin_min                           0.0875372 -2.642
    ## strata(tgroup)tgroup=2:Albumin_min                           0.0932299  0.276
    ## strata(tgroup)tgroup=1:Bilirubin_max                         0.0081724  3.518
    ## strata(tgroup)tgroup=2:Bilirubin_max                         0.0173879 -0.919
    ## strata(tgroup)tgroup=1:GCS_max                               0.0157330 -8.147
    ## strata(tgroup)tgroup=2:GCS_max                               0.0190784 -3.598
    ## strata(tgroup)tgroup=1:HCO3_min                              0.0117341 -0.283
    ## strata(tgroup)tgroup=2:HCO3_min                              0.0123778  3.159
    ## strata(tgroup)tgroup=1:HR_min                                0.0032554  2.504
    ## strata(tgroup)tgroup=2:HR_min                                0.0038581  0.338
    ## strata(tgroup)tgroup=1:Lactate_max                           0.0202818  4.457
    ## strata(tgroup)tgroup=2:Lactate_max                           0.0342960 -0.039
    ##                                                                         Pr(>|z|)
    ## Age                                                         < 0.0000000000000002
    ## BUN_max                                                     0.000000000000000636
    ## Na_max                                                      0.000000285293278950
    ## pH_min                                                                  0.037042
    ## Temp_max                                                                0.002410
    ## Urine_min                                                               0.036316
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=1                        0.896134
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=1 0.000000015146402643
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=1                               0.125752
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=1                                    NA
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=2                        0.730037
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=2             0.084477
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=2                               0.000263
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=2                                    NA
    ## strata(tgroup)tgroup=1:Albumin_min                                      0.008249
    ## strata(tgroup)tgroup=2:Albumin_min                                      0.782708
    ## strata(tgroup)tgroup=1:Bilirubin_max                                    0.000434
    ## strata(tgroup)tgroup=2:Bilirubin_max                                    0.358295
    ## strata(tgroup)tgroup=1:GCS_max                              0.000000000000000372
    ## strata(tgroup)tgroup=2:GCS_max                                          0.000320
    ## strata(tgroup)tgroup=1:HCO3_min                                         0.776925
    ## strata(tgroup)tgroup=2:HCO3_min                                         0.001581
    ## strata(tgroup)tgroup=1:HR_min                                           0.012291
    ## strata(tgroup)tgroup=2:HR_min                                           0.735142
    ## strata(tgroup)tgroup=1:Lactate_max                          0.000008293318325089
    ## strata(tgroup)tgroup=2:Lactate_max                                      0.968577
    ##                                                                
    ## Age                                                         ***
    ## BUN_max                                                     ***
    ## Na_max                                                      ***
    ## pH_min                                                      *  
    ## Temp_max                                                    ** 
    ## Urine_min                                                   *  
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=1               
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=1 ***
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=1                      
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=1                     
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=2               
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=2 .  
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=2                   ***
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=2                     
    ## strata(tgroup)tgroup=1:Albumin_min                          ** 
    ## strata(tgroup)tgroup=2:Albumin_min                             
    ## strata(tgroup)tgroup=1:Bilirubin_max                        ***
    ## strata(tgroup)tgroup=2:Bilirubin_max                           
    ## strata(tgroup)tgroup=1:GCS_max                              ***
    ## strata(tgroup)tgroup=2:GCS_max                              ***
    ## strata(tgroup)tgroup=1:HCO3_min                                
    ## strata(tgroup)tgroup=2:HCO3_min                             ** 
    ## strata(tgroup)tgroup=1:HR_min                               *  
    ## strata(tgroup)tgroup=2:HR_min                                  
    ## strata(tgroup)tgroup=1:Lactate_max                          ***
    ## strata(tgroup)tgroup=2:Lactate_max                             
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ##                                                             exp(coef)
    ## Age                                                            1.0351
    ## BUN_max                                                        1.0112
    ## Na_max                                                         0.9604
    ## pH_min                                                         0.6620
    ## Temp_max                                                       0.8536
    ## Urine_min                                                      0.9980
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=1               1.0224
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=1    0.3139
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=1                      1.2225
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=1                         NA
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=2               1.0677
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=2    0.7356
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=2                      1.7269
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=2                         NA
    ## strata(tgroup)tgroup=1:Albumin_min                             0.7935
    ## strata(tgroup)tgroup=2:Albumin_min                             1.0260
    ## strata(tgroup)tgroup=1:Bilirubin_max                           1.0292
    ## strata(tgroup)tgroup=2:Bilirubin_max                           0.9842
    ## strata(tgroup)tgroup=1:GCS_max                                 0.8797
    ## strata(tgroup)tgroup=2:GCS_max                                 0.9337
    ## strata(tgroup)tgroup=1:HCO3_min                                0.9967
    ## strata(tgroup)tgroup=2:HCO3_min                                1.0399
    ## strata(tgroup)tgroup=1:HR_min                                  1.0082
    ## strata(tgroup)tgroup=2:HR_min                                  1.0013
    ## strata(tgroup)tgroup=1:Lactate_max                             1.0946
    ## strata(tgroup)tgroup=2:Lactate_max                             0.9986
    ##                                                             exp(-coef)
    ## Age                                                             0.9661
    ## BUN_max                                                         0.9889
    ## Na_max                                                          1.0413
    ## pH_min                                                          1.5106
    ## Temp_max                                                        1.1715
    ## Urine_min                                                       1.0020
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=1                0.9781
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=1     3.1856
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=1                       0.8180
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=1                          NA
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=2                0.9366
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=2     1.3595
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=2                       0.5791
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=2                          NA
    ## strata(tgroup)tgroup=1:Albumin_min                              1.2602
    ## strata(tgroup)tgroup=2:Albumin_min                              0.9746
    ## strata(tgroup)tgroup=1:Bilirubin_max                            0.9717
    ## strata(tgroup)tgroup=2:Bilirubin_max                            1.0161
    ## strata(tgroup)tgroup=1:GCS_max                                  1.1368
    ## strata(tgroup)tgroup=2:GCS_max                                  1.0711
    ## strata(tgroup)tgroup=1:HCO3_min                                 1.0033
    ## strata(tgroup)tgroup=2:HCO3_min                                 0.9616
    ## strata(tgroup)tgroup=1:HR_min                                   0.9919
    ## strata(tgroup)tgroup=2:HR_min                                   0.9987
    ## strata(tgroup)tgroup=1:Lactate_max                              0.9136
    ## strata(tgroup)tgroup=2:Lactate_max                              1.0014
    ##                                                             lower .95 upper .95
    ## Age                                                            1.0296    1.0407
    ## BUN_max                                                        1.0085    1.0139
    ## Na_max                                                         0.9456    0.9753
    ## pH_min                                                         0.4492    0.9755
    ## Temp_max                                                       0.7706    0.9455
    ## Urine_min                                                      0.9962    0.9999
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=1               0.7335    1.4250
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=1    0.2102    0.4689
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=1                      0.9453    1.5809
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=1                         NA        NA
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=2               0.7359    1.5492
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=2    0.5189    1.0427
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=2                      1.2878    2.3158
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=2                         NA        NA
    ## strata(tgroup)tgroup=1:Albumin_min                             0.6684    0.9421
    ## strata(tgroup)tgroup=2:Albumin_min                             0.8547    1.2318
    ## strata(tgroup)tgroup=1:Bilirubin_max                           1.0128    1.0458
    ## strata(tgroup)tgroup=2:Bilirubin_max                           0.9512    1.0183
    ## strata(tgroup)tgroup=1:GCS_max                                 0.8530    0.9072
    ## strata(tgroup)tgroup=2:GCS_max                                 0.8994    0.9692
    ## strata(tgroup)tgroup=1:HCO3_min                                0.9740    1.0199
    ## strata(tgroup)tgroup=2:HCO3_min                                1.0150    1.0654
    ## strata(tgroup)tgroup=1:HR_min                                  1.0018    1.0146
    ## strata(tgroup)tgroup=2:HR_min                                  0.9938    1.0089
    ## strata(tgroup)tgroup=1:Lactate_max                             1.0520    1.1390
    ## strata(tgroup)tgroup=2:Lactate_max                             0.9337    1.0681
    ## 
    ## Concordance= 0.749  (se = 0.009 )
    ## Likelihood ratio test= 577.1  on 24 df,   p=<0.0000000000000002
    ## Wald test            = 558.2  on 24 df,   p=<0.0000000000000002
    ## Score (logrank) test = 607.6  on 24 df,   p=<0.0000000000000002

    Final model diagnostics:

    # PH test
    cox.zph(ICU.final.cox, terms=FALSE)
    ##                                                                 chisq df      p
    ## Age                                                          0.141243  1 0.7070
    ## BUN_max                                                      0.175156  1 0.6756
    ## Na_max                                                       0.456307  1 0.4994
    ## pH_min                                                       0.198734  1 0.6557
    ## Temp_max                                                     0.408536  1 0.5227
    ## Urine_min                                                    1.609218  1 0.2046
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=1             0.005054  1 0.9433
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=1  0.638643  1 0.4242
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=1                    0.000111  1 0.9916
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=2             0.123591  1 0.7252
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=2  2.076903  1 0.1495
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=2                    0.548959  1 0.4587
    ## strata(tgroup)tgroup=1:Albumin_min                           2.240730  1 0.1344
    ## strata(tgroup)tgroup=2:Albumin_min                           0.001434  1 0.9698
    ## strata(tgroup)tgroup=1:Bilirubin_max                         0.849315  1 0.3567
    ## strata(tgroup)tgroup=2:Bilirubin_max                         3.264521  1 0.0708
    ## strata(tgroup)tgroup=1:GCS_max                              10.385598  1 0.0013
    ## strata(tgroup)tgroup=2:GCS_max                               2.498280  1 0.1140
    ## strata(tgroup)tgroup=1:HCO3_min                              4.521139  1 0.0335
    ## strata(tgroup)tgroup=2:HCO3_min                              1.519178  1 0.2177
    ## strata(tgroup)tgroup=1:HR_min                                1.125927  1 0.2886
    ## strata(tgroup)tgroup=2:HR_min                                0.356000  1 0.5507
    ## strata(tgroup)tgroup=1:Lactate_max                           4.188790  1 0.0407
    ## strata(tgroup)tgroup=2:Lactate_max                           5.769251  1 0.0163
    ## GLOBAL                                                      34.296951 24 0.0795
    # Graph of Schoenfeld residuals
    #ggcoxzph(cox.zph(ICU.final.cox, terms=FALSE))
    ggcoxdiagnostics(ICU.final.cox, type = "schoenfeld", title = "Diagnostic plot")
    ## `geom_smooth()` using formula 'y ~ x'

    Final Model Diagnostics:

    1. Proportional Hazards Assumptions
    • Proportional hazard assumption is supported by a non-significant relationship between residuals and time, while a significant relationship favours the null of non-constant hazards. The global test on the final model is not statistically significant (p-value is 0.08). Therefore, there does not appear to be a violation of the proportional hazards assumption.

    • The output from the proportional hazards test shows that the test is statistically significant at a 5% significance level for GCS_max, HCO3_min, and Lactate_max, though improved from before incorporating time x covariate split.

    1. Schoenfeld Residuals

    The Schoenfeld residuals represent the difference between the observed covariates and expected value for the individuals who failed (i.e. did not survive). In the graphs of the scaled Schoenfeld residuals, the blue dotted line is a smoothing spline fit to the residuals (black dots), with the dashed red line representing the zero line. Systematic departures from the red horizontal line are indicative of non-proportional hazards, since proportional hazards assumes that estimates do not vary much over time. Graphical inspection does not show systematic departures from the zero line over time.

    Re-fitting the model to the original data:

    ##Compare model on df0 to df1
    
    nm_icu_model_df0 <- na.omit(subset(icu_patients_df0, 
                                        select=c(Days, Status, # the survival object variables
                                                 RecordID, # keep record id for reference if needed
                                                 Age,  ICUType, 
                                                 Albumin_min, Bilirubin_max, BUN_max, GCS_max, HCO3_min, HR_min, Lactate_max, Na_max, pH_min,
                                                 Temp_max, Urine_min)))
    
    dim(nm_icu_model_df0)
    ## [1] 299  16
    ICUdf0.split <- survSplit(Surv(Days, Status) ~ ., data = nm_icu_model_df0, cut=c(90), episode= "tgroup", id="id2")
    head(icu_patients_df0)
    ##   RecordID Length_of_stay SAPS1 SOFA Survival in_hospital_death Days Status Age
    ## 1   132539              5     6    1       NA                 0 2408  FALSE  54
    ## 2   132540              8    16    8       NA                 0 2408  FALSE  76
    ## 3   132541             19    21   11       NA                 0 2408  FALSE  44
    ## 4   132543              9     7    1      575                 0  575   TRUE  68
    ## 5   132545              4    17    2      918                 0  918   TRUE  88
    ## 6   132547              6    14   11     1637                 0 1637   TRUE  64
    ##   Albumin_diff Albumin_max Albumin_min  ALP_diff ALP_max ALP_min  ALT_diff
    ## 1           NA          NA          NA        NA      NA      NA        NA
    ## 2           NA          NA          NA        NA      NA      NA        NA
    ## 3    0.6813367         2.7         2.3 31.147964     127     105  45.44617
    ## 4    1.4186633         4.4         4.4  9.147964     105     105 108.44617
    ## 5           NA          NA          NA        NA      NA      NA        NA
    ## 6           NA          NA          NA  5.147964     101     101  75.44617
    ##   ALT_max ALT_min  AST_diff AST_max AST_min Bilirubin_diff Bilirubin_max
    ## 1      NA      NA        NA      NA      NA             NA            NA
    ## 2      NA      NA        NA      NA      NA             NA            NA
    ## 3      91      75  65.64729     235     164       1.235961           3.0
    ## 4      12      12 154.35271      15      15       1.564039           0.2
    ## 5      NA      NA        NA      NA      NA             NA            NA
    ## 6      60      45 122.35271     162      47       1.364039           0.4
    ##   Bilirubin_min  BUN_diff BUN_max BUN_min Cholesterol_diff Cholesterol_max
    ## 1            NA 11.527053      13      13               NA              NA
    ## 2            NA  8.527053      18      16               NA              NA
    ## 3           2.8 21.527053       8       3               NA              NA
    ## 4           0.2  4.527053      23      20               NA              NA
    ## 5            NA 20.472947      45      45               NA              NA
    ## 6           0.4  9.527053      19      15         55.57724             212
    ##   Cholesterol_min Creatinine_diff Creatinine_max Creatinine_min DiasABP_diff
    ## 1              NA       0.4324463            0.8            0.8           NA
    ## 2              NA       0.4324463            1.2            0.8     26.54421
    ## 3              NA       0.9324463            0.4            0.3           NA
    ## 4              NA       0.5324463            0.9            0.7           NA
    ## 5              NA       0.2324463            1.0            1.0           NA
    ## 6             212       0.3324463            1.4            0.9     20.45579
    ##   DiasABP_max DiasABP_min  FiO2_diff FiO2_max FiO2_min GCS_diff GCS_max GCS_min
    ## 1          NA          NA         NA       NA       NA 3.755971      15      15
    ## 2          81          32 0.44807988      1.0      0.4 8.244029      15       3
    ## 3          NA          NA 0.44807988      1.0      0.5 6.244029       8       5
    ## 4          NA          NA         NA       NA       NA 3.755971      15      14
    ## 5          NA          NA         NA       NA       NA 3.755971      15      15
    ## 6          79          55 0.05192012      0.5      0.5 4.244029       9       7
    ##   Gender Glucose_diff Glucose_max Glucose_min HCO3_diff HCO3_max HCO3_min
    ## 1 Female     65.14446         205         205  3.227452       26       26
    ## 2   Male     34.85554         105         105  1.772548       22       21
    ## 3 Female     20.85554         141         119  3.227452       26       24
    ## 4   Male     33.85554         129         106  5.227452       28       27
    ## 5 Female     26.85554         113         113  4.772548       18       18
    ## 6   Male    124.14446         264         197  3.772548       19       19
    ##    HCT_diff HCT_max HCT_min Height   HR_diff HR_max HR_min
    ## 1  2.739871    33.7    33.5   -Inf 29.077891     80     58
    ## 2  6.260129    29.7    24.7  175.3  7.077891     88     80
    ## 3  4.260129    28.5    26.7   -Inf 30.077891    113     57
    ## 4 10.339871    41.3    36.1  180.3 30.077891     88     57
    ## 5  8.360129    30.8    22.6   -Inf 20.077891     94     67
    ## 6 10.639871    41.6    36.8  180.3 16.077891     91     71
    ##                         ICUType    K_diff K_max K_min Lactate_diff Lactate_max
    ## 1                  Surgical ICU 0.2647934   4.4   4.4           NA          NA
    ## 2 Cardiac Surgery Recovery Unit 0.1647934   4.3   4.3           NA          NA
    ## 3                   Medical ICU 4.4647934   8.6   3.3     1.496404         1.9
    ## 4                   Medical ICU 0.1352066   4.2   4.0           NA          NA
    ## 5                   Medical ICU 1.8647934   6.0   3.8           NA          NA
    ## 6            Coronary Care Unit 0.9647934   5.1   3.8           NA          NA
    ##   Lactate_min MAP_diff MAP_max MAP_min   Mg_diff Mg_max Mg_min   Na_diff Na_max
    ## 1          NA       NA      NA      NA 0.4842982    1.5    1.5 2.2066071    137
    ## 2          NA 34.76836     100      43 1.1157018    3.1    1.9 0.2066071    139
    ## 3         1.3       NA      NA      NA 0.6842982    1.9    1.3 2.2066071    140
    ## 4          NA       NA      NA      NA 0.1157018    2.1    2.1 1.7933929    141
    ## 5          NA       NA      NA      NA 0.4842982    1.5    1.5 0.7933929    140
    ## 6          NA 24.23164     102      62 0.2842982    1.7    1.7 2.2066071    141
    ##   Na_min NIDiasABP_diff NIDiasABP_max NIDiasABP_min NIMAP_diff NIMAP_max
    ## 1    137       17.49101            65            40   17.04069     92.33
    ## 2    139       19.49101            65            38   26.38069     86.33
    ## 3    137       37.50899            95            66   34.28931    110.00
    ## 4    140       23.50899            81            54   24.98931    100.70
    ## 5    140       38.50899            96            29   29.98931    105.70
    ## 6    137       31.50899            89            52   26.58931    102.30
    ##   NIMAP_min NISysABP_diff NISysABP_max NISysABP_min PaCO2_diff PaCO2_max
    ## 1     58.67      40.30125          157           96         NA        NA
    ## 2     49.33      44.69875          129           72   7.335797        41
    ## 3     83.33      33.30125          150          111   3.335797        37
    ## 4     73.00      23.30125          140          102         NA        NA
    ## 5     63.67      39.30125          156          119         NA        NA
    ## 6     61.67      35.69875          129           81   5.335797        45
    ##   PaCO2_min PaO2_diff PaO2_max PaO2_min    pH_diff pH_max pH_min Platelets_diff
    ## 1        NA        NA       NA       NA         NA     NA     NA       31.23069
    ## 2        33 286.38211      445       89 0.08011376   7.45   7.34       36.23069
    ## 3        37  93.61789       65       65 0.14011376   7.51   7.51      117.76931
    ## 4        NA        NA       NA       NA         NA     NA     NA      201.23069
    ## 5        NA        NA       NA       NA         NA     NA     NA       80.76931
    ## 6        35  80.61789      101       78 0.07988624   7.40   7.29       86.23069
    ##   Platelets_max Platelets_min RespRate_diff RespRate_max RespRate_min SaO2_diff
    ## 1           221           221       7.34858           24           12        NA
    ## 2           226           164            NA           NA           NA  1.753921
    ## 3            84            72            NA           NA           NA  2.246079
    ## 4           391           315       7.34858           21           12        NA
    ## 5           109           109       6.65142           26           15        NA
    ## 6           276           219            NA           NA           NA  1.246079
    ##   SaO2_max SaO2_min SysABP_diff SysABP_max SysABP_min Temp_diff Temp_max
    ## 1       NA       NA          NA         NA         NA  1.874083     38.1
    ## 2       99       97     50.3105        135         66  2.474083     37.9
    ## 3       95       95          NA         NA         NA  2.025917     39.0
    ## 4       NA       NA          NA         NA         NA  1.874083     36.7
    ## 5       NA       NA          NA         NA         NA  1.174083     37.8
    ## 6       97       96     43.3105        152         73  1.174083     37.8
    ##   Temp_min TroponinI_diff TroponinI_max TroponinI_min TroponinT_diff
    ## 1     35.1             NA            NA            NA             NA
    ## 2     34.5             NA            NA            NA             NA
    ## 3     36.7             NA            NA            NA             NA
    ## 4     35.1             NA            NA            NA             NA
    ## 5     35.8             NA            NA            NA             NA
    ## 6     35.8       4.142945           1.3           1.3             NA
    ##   TroponinT_max TroponinT_min Urine_diff Urine_max Urine_min   WBC_diff WBC_max
    ## 1            NA            NA  800.78242       900        30  0.9331524    11.2
    ## 2            NA            NA  670.78242       770         0  4.7331524    13.1
    ## 3            NA            NA  310.78242       410        30  8.4331524     4.2
    ## 4            NA            NA  600.78242       700       100  3.3331524    11.5
    ## 5            NA            NA   83.21758       150        16  8.3331524     3.8
    ## 6            NA            NA 1100.78242      1200        40 11.8668476    24.0
    ##   WBC_min Weight_diff Weight_max Weight_min PFratio
    ## 1    11.2         Inf       -Inf        Inf      NA
    ## 2     7.4    4.699878       80.6       76.0      89
    ## 3     3.7   23.999878       56.7       56.7      65
    ## 4     8.8    3.900122       84.6       84.6      NA
    ## 5     3.8         Inf       -Inf        Inf      NA
    ## 6    14.4   33.300122      114.0      114.0     156
    ICU.final.coxdf0 <- coxph(Surv(Days, Status) ~
                             Age + ICUType:strata(tgroup) + 
                             Albumin_min:strata(tgroup) + 
                             Bilirubin_max:strata(tgroup) + BUN_max + 
                             GCS_max:strata(tgroup) + HCO3_min:strata(tgroup) + 
                             HR_min:strata(tgroup) + Lactate_max:strata(tgroup) + 
                             Na_max + pH_min + Temp_max + Urine_min,
                             data = ICUdf0.split)
    
    summary(ICU.final.coxdf0)
    ## Call:
    ## coxph(formula = Surv(Days, Status) ~ Age + ICUType:strata(tgroup) + 
    ##     Albumin_min:strata(tgroup) + Bilirubin_max:strata(tgroup) + 
    ##     BUN_max + GCS_max:strata(tgroup) + HCO3_min:strata(tgroup) + 
    ##     HR_min:strata(tgroup) + Lactate_max:strata(tgroup) + Na_max + 
    ##     pH_min + Temp_max + Urine_min, data = ICUdf0.split)
    ## 
    ##   n= 521, number of events= 123 
    ## 
    ##                                                                   coef
    ## Age                                                          0.0308044
    ## BUN_max                                                      0.0100748
    ## Na_max                                                      -0.0292607
    ## pH_min                                                      -1.9164019
    ## Temp_max                                                     0.0199181
    ## Urine_min                                                    0.0005413
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=1             0.4507477
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=1 -2.4418221
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=1                    0.4491899
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=1                          NA
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=2            -0.3107640
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=2  0.3418326
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=2                    0.7695124
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=2                          NA
    ## strata(tgroup)tgroup=1:Albumin_min                          -0.4813815
    ## strata(tgroup)tgroup=2:Albumin_min                          -0.5003112
    ## strata(tgroup)tgroup=1:Bilirubin_max                         0.0396806
    ## strata(tgroup)tgroup=2:Bilirubin_max                         0.0404057
    ## strata(tgroup)tgroup=1:GCS_max                              -0.0875339
    ## strata(tgroup)tgroup=2:GCS_max                               0.0024367
    ## strata(tgroup)tgroup=1:HCO3_min                              0.0131254
    ## strata(tgroup)tgroup=2:HCO3_min                              0.0986484
    ## strata(tgroup)tgroup=1:HR_min                                0.0093436
    ## strata(tgroup)tgroup=2:HR_min                               -0.0102991
    ## strata(tgroup)tgroup=1:Lactate_max                           0.0666912
    ## strata(tgroup)tgroup=2:Lactate_max                          -0.0140842
    ##                                                              exp(coef)
    ## Age                                                          1.0312838
    ## BUN_max                                                      1.0101257
    ## Na_max                                                       0.9711633
    ## pH_min                                                       0.1471354
    ## Temp_max                                                     1.0201178
    ## Urine_min                                                    1.0005414
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=1             1.5694852
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=1  0.0870022
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=1                    1.5670422
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=1                          NA
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=2             0.7328868
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=2  1.4075247
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=2                    2.1587134
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=2                          NA
    ## strata(tgroup)tgroup=1:Albumin_min                           0.6179291
    ## strata(tgroup)tgroup=2:Albumin_min                           0.6063419
    ## strata(tgroup)tgroup=1:Bilirubin_max                         1.0404784
    ## strata(tgroup)tgroup=2:Bilirubin_max                         1.0412331
    ## strata(tgroup)tgroup=1:GCS_max                               0.9161878
    ## strata(tgroup)tgroup=2:GCS_max                               1.0024397
    ## strata(tgroup)tgroup=1:HCO3_min                              1.0132119
    ## strata(tgroup)tgroup=2:HCO3_min                              1.1036782
    ## strata(tgroup)tgroup=1:HR_min                                1.0093873
    ## strata(tgroup)tgroup=2:HR_min                                0.9897538
    ## strata(tgroup)tgroup=1:Lactate_max                           1.0689654
    ## strata(tgroup)tgroup=2:Lactate_max                           0.9860145
    ##                                                               se(coef)      z
    ## Age                                                          0.0062516  4.927
    ## BUN_max                                                      0.0028836  3.494
    ## Na_max                                                       0.0203191 -1.440
    ## pH_min                                                       0.9990481 -1.918
    ## Temp_max                                                     0.1206279  0.165
    ## Urine_min                                                    0.0032598  0.166
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=1             0.4818259  0.935
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=1  1.0372018 -2.354
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=1                    0.2896715  1.551
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=1                   0.0000000     NA
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=2             0.8194792 -0.379
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=2  0.5020358  0.681
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=2                    0.4141223  1.858
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=2                   0.0000000     NA
    ## strata(tgroup)tgroup=1:Albumin_min                           0.2051333 -2.347
    ## strata(tgroup)tgroup=2:Albumin_min                           0.2791597 -1.792
    ## strata(tgroup)tgroup=1:Bilirubin_max                         0.0177289  2.238
    ## strata(tgroup)tgroup=2:Bilirubin_max                         0.0400231  1.010
    ## strata(tgroup)tgroup=1:GCS_max                               0.0348508 -2.512
    ## strata(tgroup)tgroup=2:GCS_max                               0.0474839  0.051
    ## strata(tgroup)tgroup=1:HCO3_min                              0.0246870  0.532
    ## strata(tgroup)tgroup=2:HCO3_min                              0.0294466  3.350
    ## strata(tgroup)tgroup=1:HR_min                                0.0076902  1.215
    ## strata(tgroup)tgroup=2:HR_min                                0.0112699 -0.914
    ## strata(tgroup)tgroup=1:Lactate_max                           0.0444354  1.501
    ## strata(tgroup)tgroup=2:Lactate_max                           0.0747284 -0.188
    ##                                                                Pr(>|z|)    
    ## Age                                                         0.000000833 ***
    ## BUN_max                                                        0.000476 ***
    ## Na_max                                                         0.149851    
    ## pH_min                                                         0.055082 .  
    ## Temp_max                                                       0.868849    
    ## Urine_min                                                      0.868123    
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=1               0.349531    
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=1    0.018561 *  
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=1                      0.120977    
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=1                           NA    
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=2               0.704524    
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=2    0.495939    
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=2                      0.063144 .  
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=2                           NA    
    ## strata(tgroup)tgroup=1:Albumin_min                             0.018942 *  
    ## strata(tgroup)tgroup=2:Albumin_min                             0.073100 .  
    ## strata(tgroup)tgroup=1:Bilirubin_max                           0.025209 *  
    ## strata(tgroup)tgroup=2:Bilirubin_max                           0.312706    
    ## strata(tgroup)tgroup=1:GCS_max                                 0.012016 *  
    ## strata(tgroup)tgroup=2:GCS_max                                 0.959074    
    ## strata(tgroup)tgroup=1:HCO3_min                                0.594952    
    ## strata(tgroup)tgroup=2:HCO3_min                                0.000808 ***
    ## strata(tgroup)tgroup=1:HR_min                                  0.224367    
    ## strata(tgroup)tgroup=2:HR_min                                  0.360793    
    ## strata(tgroup)tgroup=1:Lactate_max                             0.133392    
    ## strata(tgroup)tgroup=2:Lactate_max                             0.850507    
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ##                                                             exp(coef)
    ## Age                                                            1.0313
    ## BUN_max                                                        1.0101
    ## Na_max                                                         0.9712
    ## pH_min                                                         0.1471
    ## Temp_max                                                       1.0201
    ## Urine_min                                                      1.0005
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=1               1.5695
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=1    0.0870
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=1                      1.5670
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=1                         NA
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=2               0.7329
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=2    1.4075
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=2                      2.1587
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=2                         NA
    ## strata(tgroup)tgroup=1:Albumin_min                             0.6179
    ## strata(tgroup)tgroup=2:Albumin_min                             0.6063
    ## strata(tgroup)tgroup=1:Bilirubin_max                           1.0405
    ## strata(tgroup)tgroup=2:Bilirubin_max                           1.0412
    ## strata(tgroup)tgroup=1:GCS_max                                 0.9162
    ## strata(tgroup)tgroup=2:GCS_max                                 1.0024
    ## strata(tgroup)tgroup=1:HCO3_min                                1.0132
    ## strata(tgroup)tgroup=2:HCO3_min                                1.1037
    ## strata(tgroup)tgroup=1:HR_min                                  1.0094
    ## strata(tgroup)tgroup=2:HR_min                                  0.9898
    ## strata(tgroup)tgroup=1:Lactate_max                             1.0690
    ## strata(tgroup)tgroup=2:Lactate_max                             0.9860
    ##                                                             exp(-coef)
    ## Age                                                             0.9697
    ## BUN_max                                                         0.9900
    ## Na_max                                                          1.0297
    ## pH_min                                                          6.7965
    ## Temp_max                                                        0.9803
    ## Urine_min                                                       0.9995
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=1                0.6372
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=1    11.4940
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=1                       0.6381
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=1                          NA
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=2                1.3645
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=2     0.7105
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=2                       0.4632
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=2                          NA
    ## strata(tgroup)tgroup=1:Albumin_min                              1.6183
    ## strata(tgroup)tgroup=2:Albumin_min                              1.6492
    ## strata(tgroup)tgroup=1:Bilirubin_max                            0.9611
    ## strata(tgroup)tgroup=2:Bilirubin_max                            0.9604
    ## strata(tgroup)tgroup=1:GCS_max                                  1.0915
    ## strata(tgroup)tgroup=2:GCS_max                                  0.9976
    ## strata(tgroup)tgroup=1:HCO3_min                                 0.9870
    ## strata(tgroup)tgroup=2:HCO3_min                                 0.9061
    ## strata(tgroup)tgroup=1:HR_min                                   0.9907
    ## strata(tgroup)tgroup=2:HR_min                                   1.0104
    ## strata(tgroup)tgroup=1:Lactate_max                              0.9355
    ## strata(tgroup)tgroup=2:Lactate_max                              1.0142
    ##                                                             lower .95 upper .95
    ## Age                                                           1.01872    1.0440
    ## BUN_max                                                       1.00443    1.0159
    ## Na_max                                                        0.93325    1.0106
    ## pH_min                                                        0.02076    1.0426
    ## Temp_max                                                      0.80533    1.2922
    ## Urine_min                                                     0.99417    1.0070
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=1              0.61042    4.0354
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=1   0.01139    0.6644
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=1                     0.88820    2.7647
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=1                         NA        NA
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=2              0.14706    3.6524
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=2   0.52617    3.7652
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=2                     0.95872    4.8607
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=2                         NA        NA
    ## strata(tgroup)tgroup=1:Albumin_min                            0.41336    0.9237
    ## strata(tgroup)tgroup=2:Albumin_min                            0.35083    1.0479
    ## strata(tgroup)tgroup=1:Bilirubin_max                          1.00494    1.0773
    ## strata(tgroup)tgroup=2:Bilirubin_max                          0.96268    1.1262
    ## strata(tgroup)tgroup=1:GCS_max                                0.85570    0.9810
    ## strata(tgroup)tgroup=2:GCS_max                                0.91336    1.1002
    ## strata(tgroup)tgroup=1:HCO3_min                               0.96535    1.0634
    ## strata(tgroup)tgroup=2:HCO3_min                               1.04178    1.1693
    ## strata(tgroup)tgroup=1:HR_min                                 0.99429    1.0247
    ## strata(tgroup)tgroup=2:HR_min                                 0.96813    1.0119
    ## strata(tgroup)tgroup=1:Lactate_max                            0.97981    1.1662
    ## strata(tgroup)tgroup=2:Lactate_max                            0.85168    1.1415
    ## 
    ## Concordance= 0.756  (se = 0.021 )
    ## Likelihood ratio test= 106.4  on 24 df,   p=0.000000000002
    ## Wald test            = 94.65  on 24 df,   p=0.0000000002
    ## Score (logrank) test = 104.6  on 24 df,   p=0.000000000005
    summary(ICU.final.cox)
    ## Call:
    ## coxph(formula = Surv(Days, Status) ~ Age + ICUType:strata(tgroup) + 
    ##     Albumin_min:strata(tgroup) + Bilirubin_max:strata(tgroup) + 
    ##     BUN_max + GCS_max:strata(tgroup) + HCO3_min:strata(tgroup) + 
    ##     HR_min:strata(tgroup) + Lactate_max:strata(tgroup) + Na_max + 
    ##     pH_min + Temp_max + Urine_min, data = ICU.split_noutliers)
    ## 
    ##   n= 3444, number of events= 721 
    ## 
    ##                                                                   coef
    ## Age                                                          0.0345124
    ## BUN_max                                                      0.0111342
    ## Na_max                                                      -0.0404555
    ## pH_min                                                      -0.4124840
    ## Temp_max                                                    -0.1582918
    ## Urine_min                                                   -0.0019812
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=1             0.0221166
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=1 -1.1586329
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=1                    0.2008633
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=1                          NA
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=2             0.0655282
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=2 -0.3071060
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=2                    0.5463547
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=2                          NA
    ## strata(tgroup)tgroup=1:Albumin_min                          -0.2312474
    ## strata(tgroup)tgroup=2:Albumin_min                           0.0257121
    ## strata(tgroup)tgroup=1:Bilirubin_max                         0.0287543
    ## strata(tgroup)tgroup=2:Bilirubin_max                        -0.0159728
    ## strata(tgroup)tgroup=1:GCS_max                              -0.1281817
    ## strata(tgroup)tgroup=2:GCS_max                              -0.0686489
    ## strata(tgroup)tgroup=1:HCO3_min                             -0.0033246
    ## strata(tgroup)tgroup=2:HCO3_min                              0.0391071
    ## strata(tgroup)tgroup=1:HR_min                                0.0081504
    ## strata(tgroup)tgroup=2:HR_min                                0.0013052
    ## strata(tgroup)tgroup=1:Lactate_max                           0.0904054
    ## strata(tgroup)tgroup=2:Lactate_max                          -0.0013510
    ##                                                              exp(coef)
    ## Age                                                          1.0351149
    ## BUN_max                                                      1.0111965
    ## Na_max                                                       0.9603519
    ## pH_min                                                       0.6620038
    ## Temp_max                                                     0.8536006
    ## Urine_min                                                    0.9980208
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=1             1.0223630
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=1  0.3139150
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=1                    1.2224577
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=1                          NA
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=2             1.0677228
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=2  0.7355726
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=2                    1.7269462
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=2                          NA
    ## strata(tgroup)tgroup=1:Albumin_min                           0.7935431
    ## strata(tgroup)tgroup=2:Albumin_min                           1.0260455
    ## strata(tgroup)tgroup=1:Bilirubin_max                         1.0291717
    ## strata(tgroup)tgroup=2:Bilirubin_max                         0.9841541
    ## strata(tgroup)tgroup=1:GCS_max                               0.8796935
    ## strata(tgroup)tgroup=2:GCS_max                               0.9336545
    ## strata(tgroup)tgroup=1:HCO3_min                              0.9966809
    ## strata(tgroup)tgroup=2:HCO3_min                              1.0398819
    ## strata(tgroup)tgroup=1:HR_min                                1.0081837
    ## strata(tgroup)tgroup=2:HR_min                                1.0013060
    ## strata(tgroup)tgroup=1:Lactate_max                           1.0946180
    ## strata(tgroup)tgroup=2:Lactate_max                           0.9986499
    ##                                                               se(coef)      z
    ## Age                                                          0.0027499 12.550
    ## BUN_max                                                      0.0013776  8.082
    ## Na_max                                                       0.0078816 -5.133
    ## pH_min                                                       0.1978059 -2.085
    ## Temp_max                                                     0.0521644 -3.034
    ## Urine_min                                                    0.0009464 -2.093
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=1             0.1694156  0.131
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=1  0.2047092 -5.660
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=1                    0.1311915  1.531
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=1                   0.0000000     NA
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=2             0.1898951  0.345
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=2  0.1780033 -1.725
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=2                    0.1496993  3.650
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=2                   0.0000000     NA
    ## strata(tgroup)tgroup=1:Albumin_min                           0.0875372 -2.642
    ## strata(tgroup)tgroup=2:Albumin_min                           0.0932299  0.276
    ## strata(tgroup)tgroup=1:Bilirubin_max                         0.0081724  3.518
    ## strata(tgroup)tgroup=2:Bilirubin_max                         0.0173879 -0.919
    ## strata(tgroup)tgroup=1:GCS_max                               0.0157330 -8.147
    ## strata(tgroup)tgroup=2:GCS_max                               0.0190784 -3.598
    ## strata(tgroup)tgroup=1:HCO3_min                              0.0117341 -0.283
    ## strata(tgroup)tgroup=2:HCO3_min                              0.0123778  3.159
    ## strata(tgroup)tgroup=1:HR_min                                0.0032554  2.504
    ## strata(tgroup)tgroup=2:HR_min                                0.0038581  0.338
    ## strata(tgroup)tgroup=1:Lactate_max                           0.0202818  4.457
    ## strata(tgroup)tgroup=2:Lactate_max                           0.0342960 -0.039
    ##                                                                         Pr(>|z|)
    ## Age                                                         < 0.0000000000000002
    ## BUN_max                                                     0.000000000000000636
    ## Na_max                                                      0.000000285293278950
    ## pH_min                                                                  0.037042
    ## Temp_max                                                                0.002410
    ## Urine_min                                                               0.036316
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=1                        0.896134
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=1 0.000000015146402643
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=1                               0.125752
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=1                                    NA
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=2                        0.730037
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=2             0.084477
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=2                               0.000263
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=2                                    NA
    ## strata(tgroup)tgroup=1:Albumin_min                                      0.008249
    ## strata(tgroup)tgroup=2:Albumin_min                                      0.782708
    ## strata(tgroup)tgroup=1:Bilirubin_max                                    0.000434
    ## strata(tgroup)tgroup=2:Bilirubin_max                                    0.358295
    ## strata(tgroup)tgroup=1:GCS_max                              0.000000000000000372
    ## strata(tgroup)tgroup=2:GCS_max                                          0.000320
    ## strata(tgroup)tgroup=1:HCO3_min                                         0.776925
    ## strata(tgroup)tgroup=2:HCO3_min                                         0.001581
    ## strata(tgroup)tgroup=1:HR_min                                           0.012291
    ## strata(tgroup)tgroup=2:HR_min                                           0.735142
    ## strata(tgroup)tgroup=1:Lactate_max                          0.000008293318325089
    ## strata(tgroup)tgroup=2:Lactate_max                                      0.968577
    ##                                                                
    ## Age                                                         ***
    ## BUN_max                                                     ***
    ## Na_max                                                      ***
    ## pH_min                                                      *  
    ## Temp_max                                                    ** 
    ## Urine_min                                                   *  
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=1               
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=1 ***
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=1                      
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=1                     
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=2               
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=2 .  
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=2                   ***
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=2                     
    ## strata(tgroup)tgroup=1:Albumin_min                          ** 
    ## strata(tgroup)tgroup=2:Albumin_min                             
    ## strata(tgroup)tgroup=1:Bilirubin_max                        ***
    ## strata(tgroup)tgroup=2:Bilirubin_max                           
    ## strata(tgroup)tgroup=1:GCS_max                              ***
    ## strata(tgroup)tgroup=2:GCS_max                              ***
    ## strata(tgroup)tgroup=1:HCO3_min                                
    ## strata(tgroup)tgroup=2:HCO3_min                             ** 
    ## strata(tgroup)tgroup=1:HR_min                               *  
    ## strata(tgroup)tgroup=2:HR_min                                  
    ## strata(tgroup)tgroup=1:Lactate_max                          ***
    ## strata(tgroup)tgroup=2:Lactate_max                             
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ##                                                             exp(coef)
    ## Age                                                            1.0351
    ## BUN_max                                                        1.0112
    ## Na_max                                                         0.9604
    ## pH_min                                                         0.6620
    ## Temp_max                                                       0.8536
    ## Urine_min                                                      0.9980
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=1               1.0224
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=1    0.3139
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=1                      1.2225
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=1                         NA
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=2               1.0677
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=2    0.7356
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=2                      1.7269
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=2                         NA
    ## strata(tgroup)tgroup=1:Albumin_min                             0.7935
    ## strata(tgroup)tgroup=2:Albumin_min                             1.0260
    ## strata(tgroup)tgroup=1:Bilirubin_max                           1.0292
    ## strata(tgroup)tgroup=2:Bilirubin_max                           0.9842
    ## strata(tgroup)tgroup=1:GCS_max                                 0.8797
    ## strata(tgroup)tgroup=2:GCS_max                                 0.9337
    ## strata(tgroup)tgroup=1:HCO3_min                                0.9967
    ## strata(tgroup)tgroup=2:HCO3_min                                1.0399
    ## strata(tgroup)tgroup=1:HR_min                                  1.0082
    ## strata(tgroup)tgroup=2:HR_min                                  1.0013
    ## strata(tgroup)tgroup=1:Lactate_max                             1.0946
    ## strata(tgroup)tgroup=2:Lactate_max                             0.9986
    ##                                                             exp(-coef)
    ## Age                                                             0.9661
    ## BUN_max                                                         0.9889
    ## Na_max                                                          1.0413
    ## pH_min                                                          1.5106
    ## Temp_max                                                        1.1715
    ## Urine_min                                                       1.0020
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=1                0.9781
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=1     3.1856
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=1                       0.8180
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=1                          NA
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=2                0.9366
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=2     1.3595
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=2                       0.5791
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=2                          NA
    ## strata(tgroup)tgroup=1:Albumin_min                              1.2602
    ## strata(tgroup)tgroup=2:Albumin_min                              0.9746
    ## strata(tgroup)tgroup=1:Bilirubin_max                            0.9717
    ## strata(tgroup)tgroup=2:Bilirubin_max                            1.0161
    ## strata(tgroup)tgroup=1:GCS_max                                  1.1368
    ## strata(tgroup)tgroup=2:GCS_max                                  1.0711
    ## strata(tgroup)tgroup=1:HCO3_min                                 1.0033
    ## strata(tgroup)tgroup=2:HCO3_min                                 0.9616
    ## strata(tgroup)tgroup=1:HR_min                                   0.9919
    ## strata(tgroup)tgroup=2:HR_min                                   0.9987
    ## strata(tgroup)tgroup=1:Lactate_max                              0.9136
    ## strata(tgroup)tgroup=2:Lactate_max                              1.0014
    ##                                                             lower .95 upper .95
    ## Age                                                            1.0296    1.0407
    ## BUN_max                                                        1.0085    1.0139
    ## Na_max                                                         0.9456    0.9753
    ## pH_min                                                         0.4492    0.9755
    ## Temp_max                                                       0.7706    0.9455
    ## Urine_min                                                      0.9962    0.9999
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=1               0.7335    1.4250
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=1    0.2102    0.4689
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=1                      0.9453    1.5809
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=1                         NA        NA
    ## ICUTypeCoronary Care Unit:strata(tgroup)tgroup=2               0.7359    1.5492
    ## ICUTypeCardiac Surgery Recovery Unit:strata(tgroup)tgroup=2    0.5189    1.0427
    ## ICUTypeMedical ICU:strata(tgroup)tgroup=2                      1.2878    2.3158
    ## ICUTypeSurgical ICU:strata(tgroup)tgroup=2                         NA        NA
    ## strata(tgroup)tgroup=1:Albumin_min                             0.6684    0.9421
    ## strata(tgroup)tgroup=2:Albumin_min                             0.8547    1.2318
    ## strata(tgroup)tgroup=1:Bilirubin_max                           1.0128    1.0458
    ## strata(tgroup)tgroup=2:Bilirubin_max                           0.9512    1.0183
    ## strata(tgroup)tgroup=1:GCS_max                                 0.8530    0.9072
    ## strata(tgroup)tgroup=2:GCS_max                                 0.8994    0.9692
    ## strata(tgroup)tgroup=1:HCO3_min                                0.9740    1.0199
    ## strata(tgroup)tgroup=2:HCO3_min                                1.0150    1.0654
    ## strata(tgroup)tgroup=1:HR_min                                  1.0018    1.0146
    ## strata(tgroup)tgroup=2:HR_min                                  0.9938    1.0089
    ## strata(tgroup)tgroup=1:Lactate_max                             1.0520    1.1390
    ## strata(tgroup)tgroup=2:Lactate_max                             0.9337    1.0681
    ## 
    ## Concordance= 0.749  (se = 0.009 )
    ## Likelihood ratio test= 577.1  on 24 df,   p=<0.0000000000000002
    ## Wald test            = 558.2  on 24 df,   p=<0.0000000000000002
    ## Score (logrank) test = 607.6  on 24 df,   p=<0.0000000000000002

    Final paragraph (very brief as per task) - summarising the most important findings of your final model - most important values from stats output - simple clinical interpretation ***

    Findings of Final Model:

    Save, knit and submit

    Reminder: don’t forget to save this file, to knit it to check that everything works, and then submit via the drop box in OpenLearning.

    Submit your assignment

    When you have finished, and are satisfied with your assignment solutions, and this file knits without errors and the output looks the way you want, then you should submit via the drop box in OpenLearning.

    Problems?

    If you encounter problems with any part of the process described above, please contact the course convenor via OpenLearning as soon as possible so that the issues can be resolved in good time, and well before the assignment is due.

    Additional Information

    Each task attracts the indicated number of marks (out of a total of 30 marks for the assignment). The instructions are deliberately open-ended and less prescriptive than the individual assignments to allow you some latitude in what you do and how you go about the task. However, to complete the tasks and gain full marks, you only need to replicate or repeat the steps covered in the course - if you do most or all of the things described in the revalant chapters of the HDAT9600 course, full marks will be awarded.

    Note also that with respect to the model fitting, there are no right or wrong answers when it comes to variable selection and other aspects of model specification. Deep understanding of the underlying medical concepts which govern patient treatment and outcomes in ICUs is not required or assumed, although you should try to gain some understanding of each variable using the links provided. You will not be marked down if your medical justifications are not exactly correct or complete, but do you best, and don’t hesitate to seek help from the course convenor.